Support

Account

Home Forums General Issues Is it possible to sort pages by a field that is within a field group?

Solved

Is it possible to sort pages by a field that is within a field group?

  • Hi,

    I usually use just plain fields, but recently discovered the “nested” or “grouped” fields. This is great because it looks much better in the page editing than a single option per line, but I was wondering if it is possible to order a list of post by a nested field?

    Example:

    I have a parent page called “Boutiques”, and there are 20 child pages (1 for each boutique). I my ACF template I have a group called “parameters” and within this group I have a field called “location”. Is it possible to sort my child pages listing by the field “location” ?

    Thanks for your help

  • Yes,

    
    'orderby' => 'meta_value',
    'meta_key' => 'parameters_location'
    
  • Thanks, but I had tried this already and it doesn’t seem to work. It is still ordering child pages by their number order 🙁

    Here is my code if it can help:

    
    $args = array(
        'post_type'      => 'page',
        'posts_per_page' => -1,
        'post_parent'    => '13',
        'order'          => 'ASC',
        'orderby'        => 'meta_key',
        'meta_key'       => 'parameters_location'
    
     );
    
    $parent = new WP_Query( $args );
    
    if ( $parent->have_posts() ) :
    
    while ( $parent->have_posts() ) : $parent->the_post();
    
    # do this and that and display this and that
    
    endwhile;
    endif; wp_reset_postdata();
    
    ?>
    
  • aaaah! it’s ‘orderby’ => ‘meta_value’

    it works now 🙂

    Thanks

  • oops, sorry for the error

  • Can you edit your reply, I will mark it as solution

  • I edited my reply to be correct

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

The topic ‘Is it possible to sort pages by a field that is within a field group?’ is closed to new replies.