Last active
May 27, 2020 21:24
-
-
Save geckoseo/f8e8eeff837bd05630e8a8adb20e5caa to your computer and use it in GitHub Desktop.
Beaver Themer - show a Gutenberg Block using conditional logic if an ACF date field is in the future.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Events In This Program | |
function program_events() | |
{ | |
ob_start(); // start buffer | |
$documents = get_posts(array( | |
'post_type' => 'events', | |
'meta_query' => array( | |
array( | |
'key' => 'program', // name of custom field | |
'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234" | |
'compare' => 'LIKE' | |
) | |
) | |
)); | |
?> | |
<?php if ($documents) : ?> | |
<div class="post-it yellow upcoming"> | |
<div class="title">Upcoming Events</div> | |
<?php foreach ($documents as $document) : ?> | |
<?php $displaydate = get_field('display_date', $document->ID); ?> | |
<?php $locationname = get_field('location_name', $document->ID); ?> | |
<?php $locationcity = get_field('location_city', $document->ID); ?> | |
<?php $locationstate = get_field('location_state', $document->ID); ?> | |
<div class="event"> | |
<div class="eventname"><a href="<?php echo get_permalink($document->ID); ?>"><?php echo get_the_title($document->ID); ?></a></div> | |
<div class="event-icons"> | |
<span><i class="fas fa-calendar"></i><?php echo $displaydate;?></span> | |
<span class="margin-left-10"><i class="fas fa-globe-americas"></i><?php echo $locationname;?> - <?php echo $locationcity;?>, <?php echo $locationstate;?></span> | |
</div> | |
</div> | |
<?php endforeach; ?> | |
</div> | |
<?php endif; | |
$output = ob_get_clean(); // set the buffer data to variable and clean the buffer | |
return $output; | |
} | |
add_shortcode('these_events', 'program_events'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forked from Pastebin by David Zack