Support

Account

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

  • Hi,

    so what you want is get posts by state name and then when outputting them sort them by city.

    maybe you could try that, instead of having 2

    set up your $args like that:

    $args = array(
             'numberposts' => -1,
    	 'post_type' => 'OGs',
             'orderby'   => 'meta_value', 
             'order' => 'DESC',
    	 'meta_key' => 'city',
    );

    this code above should return all the OGs posts ordered by city however the states part is missing i don’t know if you can add it as below.

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

    I diden’t test that but looks like the ‘orderby’ => ‘meta_value’ is a good start.

    let me know how it goes