sudhakar
sudhakar

Reputation: 29

posts_per_page using custom value

i have created a custo post type and wp_query the custom postype like this $number_of_posts = get_option('news_blurb_blurbs_per_page_setting'); $default_posts = 3;

        $args = array(

        'post_type'      => 'all_news_blurbs',
        'orderby'        => 'date',
        'order'          => 'DESC',
        'numberposts'   => 3,
        'posts_per_page' => (isset($number_of_posts) ? $number_of_posts : $default_posts)

it works fine when custom values is selected in select tag but when black the default should be 3 is not working

Upvotes: 0

Views: 228

Answers (1)

dipmala
dipmala

Reputation: 2011

You need to add in condition like below

 $number_of_posts = get_option('news_blurb_blurbs_per_page_setting'); 

 if(!empty($number_of_posts) && $number_of_posts!='')
    $number_of_posts = 3;

That's it it will work.

Upvotes: 1

Related Questions