1

I have a front page of a site that consists of different custom post types.

To achieve this I've been using the WP_Query(); function.

In the example below, the query is used in a section and outputs the first 3 posts of the 'news' custom post type.

Is it possible to have a WP_Query where you output a certain range of posts i.e. In a different section I would like to output posts 4-6 of this same 'news' custom post type, not 1-3 (using the default published date as the criteria so it basically shows the 4th, 5th and 6th oldest posts).

Because this is dynamic content I would like it so it always shows posts 4-6 so I don't have to manually change a date range.

Any help would be amazing.

<?php 
    $homePageNews = new WP_Query(array(
        'posts_per_page' => 3,
        'post_type'=> 'news'
    ));

    while($homePageNews->have_posts()){
        $homePageNews->the_post(); ?>

            // HTML OUTPUT


<?php } ?>

<?php  wp_reset_postdata(); ?>
2

Yes, can achieve this with the offset parameter.

$homePageNews = new WP_Query( array(
    'posts_per_page' => 3,
    'offset'         => 3,
    'post_type'      => 'news'
) );

That will get 3 posts, but offset by 3, so that you get the 4th to 6th posts.

1
  • Thanks Jacob that worked a treat. Such a shame someone downvoted the question. Why do people do that? – The Chewy Jan 28 '20 at 19:10

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.