Home Forums Add-ons Repeater Field If Subfields Equals, Show Posts Reply To: If Subfields Equals, Show Posts

  • Hi, Jonathan,

    First of all, thanks for the input! I know what you mean about the deprecated code. I’m working on a WP site that someone else built. Not an excuse, but yeah.

    I used the first function you posted since I’m using only one repeater in my group. I tried using the code you posted but it’s not showing any posts in the desired area of the page. The page loads the rest of the content so there is that.

    Here’s the code I’m using based on what you shared:

    // args
    $args = array(
    	'posts_per_page'	=> 1,
    	'post_type'		=> 'profiles',
    	'meta_query'	=> array(
    		'relation'		=> 'AND',
    			'key'		=> 'repeaterfieldname_%_year',
    			'compare'	=> '=',
    			'value'		=> '2015',
    			'key'		=> 'repeaterfieldname_%_level',
    			'compare'	=> '=',
    			'value'		=> 'GRAND PRIZE',
    // query
    $the_query = new WP_Query( $args );
    <?php if( $the_query->have_posts() ): ?>
    	<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    	<section class="winner-level">
    		<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    		<?php if(get_field('awards_given')): ?>
      		<?php while(has_sub_field('awards_given')): ?>
    		<?php if( get_sub_field('year') ): ?>
    		<p><?php the_sub_field('program'); ?> - <?php the_sub_field('program_category'); ?></p>
    		<p><em><?php the_sub_field('campaign_title'); ?></em></p>
    		<p><strong><?php the_sub_field('level'); ?></strong></p>
    		<?php endif; ?>
    		<?php endwhile; ?>
     		<?php endif; ?>
    <?php endwhile; ?>
    <?php endif; ?>
    <?php wp_reset_query();	?>

    Thoughts? Note that ‘GRAND PRIZE’ is in caps in the repeater field settings, which is why I made it such in the array.