• I’m currently running wordpress 4.5 with a WooTheme called The Morning After. I decided to change a few things here and there, but encountered some issues regarding the posts_per_page argument used in the WP_query object. The intention is to show more than one post (3 or 4 posts) and ignore the category Featured articles.

    $args = array('posts_per_page'   => 1,
                  'category__not_in' => get_cat_ID('Featured articles'));
    
    $query = new WP_query('posts_per_page=1');
    
    while ( $query->have_posts() ) { $query->the_post();
    
        echo '<li>' . get_the_title() . '</li>';
    
        break;
    }
    wp_reset_postdata();

    What am I doing wrong? Result is just the latest non-Featured articles post.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter empec

    (@empec)

    Sorry, code should be:

    I’m currently running wordpress 4.5 with a WooTheme called The Morning After. I decided to change a few things here and there, but encountered some issues regarding the posts_per_page argument used in the WP_query object. The intention is to show more than one post (3 or 4 posts) and ignore the category Featured articles.

    $args = array('posts_per_page'   => 3,
                  'category__not_in' => get_cat_ID('Featured articles'));
    
    $query = new WP_query($args);
    
    while ( $query->have_posts() ) { $query->the_post();
    
        echo '<li>' . get_the_title() . '</li>';
    
        break;
    }
    wp_reset_postdata();

    What am I doing wrong? Result is just the latest non-Featured articles post.

    Thread Starter empec

    (@empec)

    It is funny that when I use the following code, the minimum number of posts in the result is 4. Even when the posts_per_page argument is set to 1, 2 or 3. When I change it to 5, the result is also 5 posts. The same counts for the above code when I remove the ‘break;’.

    $args = array(
    	'posts_per_page' => 5,
    	'category__not_in' => get_cat_ID( 'Featured articles' ));
    
    $the_query = new WP_Query( $args );
    
    while ( $the_query->have_posts() ) : $the_query->the_post();
    
    echo '<li>' . get_the_title() . '</li>';
    
    endwhile;
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show more than one post in home.’ is closed to new replies.