Skip to content

Instantly share code, notes, and snippets.

@tessak22
Created December 11, 2017 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tessak22/7640dd52b2b0bea0fcf52f906826e1b6 to your computer and use it in GitHub Desktop.
Save tessak22/7640dd52b2b0bea0fcf52f906826e1b6 to your computer and use it in GitHub Desktop.
Advanced Custom Fields IF Statements
//Used in Template
<?php if(get_field('banner_image')): ?>
<div class="banner-image"><img class="img-responsive" src="<?php the_field('banner_image'); ?>"></div>
<?php endif; ?>
//Used in custom post types
<?php
/**
* page-specific include
*/
$args = array(
'post_type' => 'events',
'nopaging' => true,
'order' => 'DESC',
'orderby' => 'date'
);
$children = new WP_Query($args);
?>
<?php if ($children->have_posts()) : ?>
<div class="events row">
<?php while ($children->have_posts()) : $children->the_post(); $fields = (object) get_fields(); ?>
<div class="event-info col-xs-12">
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<ul class="event-links">
<?php if ($fields->event_date_published) : ?>
<li class="event-date"><p><?php echo $fields->event_date_published; ?></p></li>
<?php endif; ?>
<?php if ($fields->event_pdf) : ?>
<li><p class="call-to-action"><a href="<?php echo $fields->event_pdf; ?>" target="_blank">View PDF</a></p></li>
<?php endif; ?>
<?php if ($fields->event_external_link) : ?>
<li><p class="call-to-action"><a href="<?php echo $fields->event_external_link; ?>" target="_blank">Link</a></p></li>
<?php endif; ?>
</ul>
</div>
<?php endwhile; wp_reset_postdata(); ?>
</div>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment