bojan259
bojan259

Reputation: 51

Wordpress - Exclude most recent post from loop

I'm making a blog page where the most recent post is featured and displayed differently from the other posts. I'm doing that with WP_Query->query('showposts=1'); and it's working fine. I also have wp_reset_postdata(); after the end of the while loop.

Next, I have another loop where I want to show 9 posts without the most recent one. I'm using the following code found on wpbeginner.com:

query_posts('posts_per_page=9&offset=1');
if(have_posts()) :
...

It seemed to be working fine until I checked the older posts page - it displays the same posts! I tried to add sorting by date, wp_reset_postdata(); and some other solutions, but nothing worked.

Am I missing something, or is this method flawed?

Upvotes: 0

Views: 2848

Answers (1)

Tristup
Tristup

Reputation: 3663

Its happening as because you have changed the query through query_posts functions. Please use WP_QUERY instead of it.

 $args = array(
         'post_type'=> 'post',
         'offset'=>1,
 );
 $query=new WP_Query($args);
 while ( $query->have_posts() ) : $query->the_post();

    echo get_the_ID();

 endhwhile; endif;

hope it will work for you.

Upvotes: 3

Related Questions