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