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'
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.