Is it possible to start the loop from a certain post ID? I would like to get all the post starting at a certain ID, decendingly. To explain, I have to make some assumptions first.
Assume that my WordPress database has 20 posts. Obviously, each post will have an ID, and assume that the IDs for those posts posts range from 1, to 20.
Also assume that when we load the posts through the loop, we are using everything by default. So, the loop will retrieve records/posts from 20 to 1. If we have a range restriction of 10, then page 1 will retrieve 20 to 11, and page 2 will retrieve 10 to 1.
Now, back to my question. Assume I would like to recieve records 17 to 8. Can I pass 17 to the loop somehow, and retrieve the 10 records from 17 down to 8? Is this possible?
Here are some lines of code to help understand the issue:
<?php $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'category_name' => 'news', 'posts_per_page' => 10, 'ID_VARIABLE_HERE' => 17 // I would like to be able to pass the ID, and the loop should return 10 posts (as defined in the posts_per_page), descendingly, starting at 17. ); $custom_query = new WP_Query($args); ?> <?php if ($custom_query->have_posts()): while ($custom_query->have_posts()) : $custom_query->the_post() ; ?> <article class="my-article"> <div class="my-image"><?php the_post_thumbnail(); ?></div> <div class="my-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div> <div class="my-details"><?php the_excerpt(); ?></div> </article> <?php endwhile; else: ?> <p><?php _e('No contents exist.'); ?></p> <?php endif; ?>
As you can see, I would like to pass an argument, in the
$args, that will have the ID value (17 in the example above). Read the code comment above for details of what is needed. Is it possible? If not via an argument in
$args, what is another way of doing that?