I would like a second WP_Query on a custom post type's single page to return 5 posts, starting with two before the current post, so that I get this:

  1. The-one-before-the-previous post
  2. Previous post
  3. Current post
  4. Next post
  5. The-one-after-the-next post

How can I do this? offset is only good if I know the number of the current post.

In pseudo-code it's easy:

$gallery = new WP_Query(array(
    'post_type' => 'artwork',
    'posts_per_page' => 5,
    'fake-offset' => $current->ID-2 //This is imaginary

Thanks in advance!


Instead of using the offset parameter, take a look at the post_where filter examples under the Time Parameters section of WP_Query codex page. You could just add a filter that returns posts that are less than the current post's date.

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.