Hi
I am making a post by year listing, and I need to add a switch, I have the listing working, and the snippet to add the switch, but I am unable to merge the code.
Please advise
Here is the listing:
<?php if (have_posts()) : ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$today = date('Ymd');
$past_args = array(
'paged' => $paged,
'posts_per_page' => -1,
'post_type' => 'exhibition',
'meta_query' => array (
array (
'key' => 'ex_start',
'value' => $today,
'compare' => '<',
'type' => 'DATE'
)
),
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
query_posts( $past_args );
?>
<?php
echo '<div class="biotitle">' . 'Solo Exhibitions' . '</div>';
?>
<!-- PAST EXHIBITIONS -->
<?php while (have_posts()) : the_post(); ?>
<?php
$date = get_field('ex_start');
$gallery = get_field('ex_gallery_name');
$past_year = DateTime::createFromFormat('Ymd', $date);
$year = $past_year->format('Y');
// get start date
$datum1 = get_field('ex_start', false, false);
// make start date object
$datum1 = new DateTime($datum1);
// get end date
$datum2= get_field('ex_end', false, false);
// make end date object
$datum2 = new DateTime($datum2);
if ($year !== $today) { ?>
<h2><?php echo $year; ?></h2><p><br /></p><p><br /></p>
<?php } ?>
<a href="<?php the_permalink(); ?>" class="exhibit"><?php the_title(); ?> , <?php echo $gallery; ?> , <?php echo $datum1->format('j M Y'); ?> - <?php echo $datum2->format('j M Y'); ?></a>
<?php $today = $year; ?>
<?php
echo "<p><br /></p>";
?>
<?php endwhile; ?>
<?php endif; ?>
and here is the additional condition I need to merge in at the top level, the listing should only be displayed if this condition is true
<?php
$posts = get_posts(array(
'meta_query' => array(
array(
'key' => 'ex_groupsolo', // name of custom field
'value' => 'solo',
)
)
));
if( $posts ) {
//...
}
?>
I figured it out, this is resolved
$past_args = array(
'paged' => $paged,
'posts_per_page' => -1,
'post_type' => 'exhibition',
'meta_query' => array (
'relation' => 'AND',
array (
'key' => 'ex_start',
'value' => $today,
'compare' => '<',
'type' => 'DATE'
),
array(
'key' => 'ex_groupsolo', // name of custom field
'value' => 'group',
)
),
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
The topic ‘button group condition’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.