I’m using the documenation verbatim (http://codex.wp-event-organiser.com/function-eo_get_the_occurrences_of.html).
Is there something special about using the bracket syntax that I need to do or take note of? If I take out the lines with brackets, my templates restore. If I leave them in, the page doesn’t render past, as if it doesn’t know what to do with the bracketed code. For example:
$occurrences = eo_get_the_occurrences_of( $post_id );
foreach( $occurrences as $occurrence) {
$start = eo_format_datetime( $occurrence['start'] , 'jS F ga' );
echo $start;
endforeach;

Brent Barkley
Hi Brent,
You’ve opened the foreach
loop with a bracket so must be closed with one. So you can do:
foreach( $array as $element ){
}
or
foreach( $array as $element ):
endforeach;
Which you should use is largely down to personal preference and what you think makes the code easier to read. General consensus seems to be that brackets are better.

Stephen Harris
Sorry Stephen, I typed that out quickly just to give you an example. In my real life example, my foreach() syntax is correct 🙂 The foreach loop works fine when I take the bracketed code out. Through trial and error I figured out that it’s definitely choking on the [‘start’] bit.
-
This reply was modified 11 years, 2 months ago by
Brent Barkley.

Brent Barkley
Ah in that case. It sounds like eo_get_the_occurrences_of( $post_id )
is returning false. This could be because the passed $post_id
isn’t set, or is not an evet What does the following tell you:
var_dump( $post_id ); //Is this set?
var_dump( get_post_type( $post_id ) ); //is it an event//
var_dump( eo_get_the_occurrences_of( $post_id ) ); //What are its occurrences?

Stephen Harris