Support

Account

Home Forums General Issues How to sort by ACF field Reply To: How to sort by ACF field

  • Hi,
    A closing parenthesis was missing in my example

    $args = array(
        'numberposts' => -1,
        'post_type' => 'OGs',
        'orderby'   => 'meta_value', 
        'order' => 'ASC',
        'meta_key' => 'city',
        'meta_query' => array( 
          array( 
            'key' => 'state', 
            'value' => 'texas', 
             ),
         )
    );

    I tested my code in a fresh install of WP, it outputs all the posts with a state value of texas (text input custom field named state) and sort by city alphabetical (with another text input custom field named city).

    the only difference in my test is that i didn’t test with the same post_type, let me know if you still having issues.