Support

Account

Home Forums Front-end Issues WP_Query based on one custom field and order by another Reply To: WP_Query based on one custom field and order by another

  • Solved it. For reference, build the query as if your were querying multiple custom fields. This frees up the ‘meta_key’ option for use in ordering.

    Example:

    'post_type' => 'post',
    'showposts' => -1,
    'meta_query' => array(
        'relation' => 'AND',
        array(
            'key' => 'acf_field',
            'value' => 'acf_field_value',
            'compare' => '='
        )
    ),
    'meta_key' => 'acf_number_field',
    'orderby' => 'meta_value_num',
    'order' => 'ASC'