Home Forums General Issues WP Query Order By Issue


WP Query Order By Issue

  • I have a site with properties listed. First I’m sorting them by where they are located, then I want to order them by a ACF I created named the_order. I can’t quite figure out how to make it work.

    All help is appreciated

    $args = array(
    ‘post_type’ => ‘Property’,
    ‘meta_key’ => ‘the_borough’,
    ‘meta_value’ => $value[0],
    ‘orderby’ => ‘the_order’,
    ‘order’ => ‘DESC’

    $the_query = new WP_Query( $args );
    if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();

  • I was working through a similar issue based on the advice from this post and something like this example may work for you. In my case, it was a true/false field then a custom date.

    $args = array(
        'post_type' => 'Property', // post type 
        'meta_query' => array(
            borough_clause => array(
                'key' => 'the_borough', 
            order_clause => array(
                'key' => 'the_order',
        'orderby' => array(
            'borough_clause' => 'ASC', // assuming borough alphabetical
            'order_clause' => 'ASC' // assuming custom order is 1 2 3 etc
        'posts_per_page'   => -1, // inlcude if you want all posts
  • Thanks so much. I ended up using the export function right from the WP admin and that worked.

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

The topic ‘WP Query Order By Issue’ is closed to new replies.