WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
up vote 0 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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