Support

Account

Home Forums Add-ons Repeater Field the_sub_field as condition

Solved

the_sub_field as condition

  • Seems pretty simple, can’t see why this isn’t working . . .

    I have a repeater field “states” that contains a subfield “state”

    Based on a cookie value I want to display some stuff if the cookie value == state ( basically go through the sub_field array and display if it contains a value equalling the cookie value, i.e., CA == CA )

    What is happening is that all the subfield values are being displayed on the page, my inner code doesn’t fire at all.

    <?php
          // the PRODUCT LOOP
          $location = $_COOKIE['location-set'];
          $product_query = new WP_Query(array(
              'post_type'         => 'products',
              'posts_per_page'    => -1,
              'meta_key'          =>'order',
              'orderby'           =>'meta_value_num',
              'order'             =>'ASC',
          ));
          if( $product_query->have_posts() ) :
              while ( $product_query->have_posts() ) : $product_query->the_post();
                  if( get_field( 'states' ) ):
                     while( has_sub_field( 'states' ) ):
                          if( the_sub_field( 'state' ) == $location ) : 
                               //display my stuff
                          endif;
                      endwhile;
                  endif;
              endwhile;
          endif;
          wp_reset_query();  
      ?>

    Thanks in advance for any advice.

  • Change the_sub_field to get_sub_field.

  • Sometimes it just takes another set of eyes on it. 🙂

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘the_sub_field as condition’ is closed to new replies.