Comparing meta values in my template

WordPress Event Management, Calendars & Registration Forums General Question Comparing meta values in my template

This topic contains 1 reply, has 1 voice, and was last updated by  Adam Abrams 2 years, 11 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #40637

    Hi! I’ve built a customized template for displaying EO events on our site, and am using the following code for one section, which adds some widget-code HTML entered in a custom field:

    <?php $ticketCode =  get_post_meta($post->ID, 'ticketCode', true); ?>
    <?php if (!empty($ticketCode[0])  ) {
        echo '<h3 style="margin-top: 1em;">Buy Tickets</h3>';
        echo wpautop(get_post_meta($post->ID, 'ticketCode', true) ); 
    } ?>
    

    However, I want to modify this so that it only shows this section if the event is current or upcoming – i.e. if the “event_end_after” meta-value is equal to or greater than ‘today’. (I don’t want all the past films listed on the site to include the “Buy Tickets” section, and doing it this way is easier than removing all the ticket code from hundreds of listings!)

    I tried this, but it’s not working:

    <?php $ticketCode =  get_post_meta($post->ID, 'ticketCode', true); ?>
    <?php $eventEndAfter =  get_post_meta($post->ID, 'event_end_after', true); ?>
    
    <?php if (!empty($ticketCode[0]) && ($eventEndAfter >= 'today') {
        echo '<h3 style="margin-top: 1em;">Buy Tickets</h3>';
        echo wpautop(get_post_meta($post->ID, 'ticketCode', true) ); 
    } ?>
    

    Can you advise what I’m doing wrong?
    Thanks!

    Adam Abrams
    #40687

    Well, never mind! 😊 All kinds of rookie PHP mistakes in my code that a little more research quickly turned up. Used a query instead of a function… didn’t compare things correctly….etc. Sorry!

    Corrected code, for the record:

    <?php $eleventHTMLCode =  get_post_meta($post->ID, 'eleventHTMLCode', true); ?>
        <?php $eventEndAfter =  eo_get_the_end( 'Y-m-d' ); ?>
        <?php $today = date("Y-m-d"); ?>
    
        <?php if ( !empty($eleventHTMLCode[0]) &&  ($eventEndAfter >= $today) )  {
            echo '<h3 style="margin-top: 1em;">Buy Tickets!</h3>';
            echo wpautop(get_post_meta($post->ID, 'eleventHTMLCode', true) ); 
        } ?>
    
    Adam Abrams
Viewing 2 posts - 1 through 2 (of 2 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.