Conditionally display tribe_get_venue if venue exists

Home Forums Calendar Products Events Calendar PRO Conditionally display tribe_get_venue if venue exists

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1053241
    Sean Sullivan
    Participant

    Hello:

    We have a loop that outputs:

    Event Name
    Date | Venue

    To do so, I’m using something like this:

    <?php the_title();?>
    <?php echo tribe_get_start_date();?> | <?php tribe_get_venue();?>

    However, not all events have a location. Those are showing up like so:

    Event Name
    Date |

    Darn that pesky “|”!

    How can I display tribe_get_venue *only* if it has a value?

    Thank you.

    • This topic was modified 10 years, 3 months ago by Sean Sullivan.
    #1053267
    George
    Participant

    Hey @Sean,

    tribe_get_venue() will return NULL if there is no venue – you can just check if its return value is NULL in a variable and display different things based on that. A basic example would be something like this:


    $venue = tribe_get_venue( get_the_ID() );

    if ( is_null( $venue ) ) {
    // There's no venue...do relevant stuff.
    echo '';
    } else {
    // There is a venue! Echo $venue or whatever you want like normal.
    echo '| ' . $venue;
    }

    I hope this helps – tinker around with this and see if it does.

    Thanks,
    George

    #1054273
    Sean Sullivan
    Participant

    Perfect! Thanks George.

    #1054712
    George
    Participant

    Right on! Best of luck with your project and tinkering here – I’ll close up this thread for now, but come back any time and open a new thread if other issues/comments/questions/concerns arise.

    Thank you,
    George

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Conditionally display tribe_get_venue if venue exists’ is closed to new replies.