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 am trying to get the value of a custom field. The trick? I'm in the loop, currently printing out 2 of 5 for this example. I would like to get some info from 3 of 5 (or even 1 of 5) while printing out info on 2 of 5. I hope that makes sense. Any help would be great!

share|improve this question
up vote 1 down vote accepted

As you posted no code and little in the way of exactly what criteria you are using, I can't really writ functioning code but inside your Loop try:

var_dump($posts[$wp_query->current_post -1]->post_title);

That is, $posts[$wp_query->current_post -1] is the previous post. You can change -1 to plus or minus whatever value you want but the math cannot result is a figure below 0 or above your posts_per_page -1 (I think), as those don't exist. The query only gets posts on "this page". If you do need information from posts that appear on a previous or next page you will have to query for that information.

share|improve this answer
I didn't post any code because it was a very abstract question. I was looking for an approach that wasn't dependent on my code, something that I could put in any loop. You hit the nail on the head. That is what I came up with after digging a little deeper, too. Thanks! $events->posts[ $events->current_post + 1 ]; – Greg Wiley Apr 2 '13 at 1:28

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.