0

I want to show my specific category's last 3 post. I created this loop but it is showing only one post. What to do?enter image description here

  • Are you sure you have at least 3 posts that belong to the news category? Are those posts published? – Eduardo Escobar Sep 22 '19 at 12:49
  • yes bro.. all are published – imran khan Sep 22 '19 at 12:59
0

Using query_posts is asking for trouble, because its results may be unpredictable (read more about that in this post). In stead you should define a new query and loop through its results. Like this:

$args = array( 
    'category_name' => 'news',
    'posts_per_page' => '3'
    );
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        the_content();
        }
    }
wp_reset_postdata();
  • try with this bro. and its showing only last 1 post.. i need last 3 post – imran khan Sep 22 '19 at 17:07
  • That means either there are no three posts or something is using the pre_get_posts filter to modify the query. – cjbj Sep 22 '19 at 20:20
  • there are 5 posts. can you please help me out bro. – imran khan Sep 22 '19 at 20:37
  • Sorry, you'll have to do your debugging yourself, because there are too many possible sources of interference. Switch off all plugins, switch to a different theme. and see what happens – cjbj Sep 23 '19 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.