Bracket Syntax Always Breaks Template?

WordPress Event Management, Calendars & Registration Forums General Question Bracket Syntax Always Breaks Template?

This topic contains 3 replies, has 2 voices, and was last updated by  Stephen Harris 11 years, 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #8625

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

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

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

    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
Viewing 4 posts - 1 through 4 (of 4 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.