Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.