Home › Forums › General Issues › Query Posts by One Custom Field and 'orderby' Another Custom Field › Reply To: Query Posts by One Custom Field and 'orderby' Another Custom Field
Thanks, John. That document was helpful.
For someone else who may stumble across this article and find my query helpful, here it is:
$my_query = new WP_Query(array(
'category_name' => 'artist',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
'gender_clause' => array(
'key' => 'gender',
'value' => 'f',
),
'sort_clause' => array(
'key' => 'sort_name',
'compare' => 'EXISTS',
),
),
'orderby' => 'sort_clause',
'order' => 'ASC',
));
Basically, I am querying posts of the ‘artist’ category, and then selecting those posts where the ‘gender’ (a custom field I have setup) is set to the value of ‘f’. There is another custom field called ‘sort_name’ that I use to order the posts by.
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.