Support

Account

Home Forums Add-ons Repeater Field Meta Query inside a repeater field – how to

Unread

Meta Query inside a repeater field – how to

  • I have record label website with a post type called “Tourdates” and I have custom fields for ticket links, venue, location, etc, and also DATE. Now, if this site was for one band, each “Tourdate” post type entry would have all the custom fields outside of a repeater, as it’s not needed. But since there are many bands, each “Tourdate” entry IS a band. And in that entry, I have a “tourdates” repeater field. So if entry is for Guns N Roses, and they have 5 dates, you enter in 5 items in the repeater field, so when you view the Guns N Roses singular entry, you see those 5 dates. That works. I use a meta query to then ONLY show dates today or upcoming. Works!

    This works for this scenario:

    <ul>
      <?php
        $today = current_time('Ymd');
    
         args = array(
          'post_type' => 'tourdates',
          'post_status' => 'publish',
          'posts_per_page' => '150',
          'meta_query' =>
          array(
            'key' => 'showdate',
            'compare' => '>=',
            'value' => $today,
          ),
          'meta_key' => 'showdate',
          'orderby' => 'meta_value',
          'order' => 'ASC',
        );
        $query = new WP_Query($args);
    
        if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
      ?>
    
        <li class="show_event">
          // MY DATE LISTING with custom fields, showing only upcoming dates
        </li>
    
      <?php endwhile; ?>
      <?php endif; ?>
      <?php wp_reset_postdata(); ?>
    </ul>
    

    Now, since for my needs, I am using a repeater field for one entry (band) to show multiple dates, I need to put the meta query INSIDE the repeater field so only current or upcoming repeater items show. Here is what I have, but don’t know how to do the above WITHIN a repeater field of a single post type entry. Help?!

    <?php if(have_rows('tourdates')): ?>
        <?php while(have_rows('tourdates')) : the_row();
          $venue_name = get_sub_field('venuename');
          $venue_link = get_sub_field('venuelink');
          $showdate = get_sub_field('showdate');
    
          $today = current_time('Ymd');
          $metaQuery = [
            [
              'key' => 'tourdates_$_showdate',
              'compare' => '>=',
              'value' => $today,
            ],
          ];
        ?>
    
          <li class="show_event w-100 h-auto pb-4 mb-4 d-sm-flex <?php if( $soldout == true ) { echo 'soldout'; }; ?>" id="post-<?php the_ID(); ?>">
            // MY DATE LISTING with custom sub_fields
          </li>
    
      <?php endwhile; ?>
    <?php endif; ?>
    
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.