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 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

1 Answer 1

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

 
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.