Support

Account

Home Forums Add-ons Repeater Field Sorting query by subfield value

Unread

Sorting query by subfield value

  • Hi,

    I am trying to sort a wp_query based on a repeater sub_field_value.
    Even though I found multiple instructions that seems related to that topic I can’t get it to work.

    I have a repeater field ‘spieldaten’ (playtimes) with a date subfield ‘date’ (among ohter fields) on the regular post type. I am now trying to list all the playtimes ordered by date on a page.

    $args = array(
        'post_type' => 'post',
        'post_per_page' => -1,   
        'meta_key' => 'spieldaten_0_date',
        'orderby'	=> 'meta_value_num',
        'order'	=> 'DESC'
    );
    
    // get results
    $the_query = new WP_Query( $args );
    
    if( $the_query->have_posts() ):
       while ( $the_query->have_posts() ) : $the_query->the_post();
           while ( have_rows('spieldaten') ) : the_row();
              if( get_sub_field('date') ) { the_sub_field('date'); }
              /* other fields … */
           endwhile;
       endwhile;
    endif;

    What am I doing wrong?
    Thanks a lot
    L

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.