Support

Account

Home Forums ACF PRO button group condition

Helping

button group condition

  • 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'  
            
        );
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.