I'm currently setting up events in the Events Calendar plugin and need to create a (supposedly) simple list.

The list should show those details:

  • a "category header" showing the title, description and cost of the first event from that category (since those details are the same for all of the events within the same category)
  • all events from that category sorted by date

I tried achieving this by using this code on a page template: https://gist.github.com/herrherrmann/1bf98addf711fcb4d2d9

The problem: the "category header" does not fit to the event list, instead it shows the data from the previous loop. Example:

~1st loop~
title: none
description: none
cost: none
all events from 1st category

~2nd loop~
title: title from 1st category
description: description from 1st category
cost: cost from 1st category
all events from 2nd category

I understand that I'm using the get_posts function in a wrong way and maybe I have to use two loops in order to get what I need? But I currently can't think of a pattern that outputs it correctly.

Any help is greatly appreciated!

1 Answer 1


Since you know you want only the first one and you're not using a typical loop, you're already using an array of posts, you can just do setup_postdata($events[0]);

and then get your data from the first item here

then continue your loop as written if it's working as happily as expected.

  • That sounds like the right track but adding setup_postdata($events[0]); in line 27 doesn't change anything. Commented May 7, 2015 at 19:57
  • 1
    ... and the reason is that I had to put setup_postdata( $GLOBALS['post'] =& $events[0] ); - just as it is told in the (very good) function reference! Commented May 7, 2015 at 20:03

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