Home › Forums › General Issues › How to sort by ACF field › Reply To: How to sort by ACF field
Hi,
A closing parenthesis was missing in my example
$args = array(
'numberposts' => -1,
'post_type' => 'OGs',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_key' => 'city',
'meta_query' => array(
array(
'key' => 'state',
'value' => 'texas',
),
)
);
I tested my code in a fresh install of WP, it outputs all the posts with a state value of texas (text input custom field named state) and sort by city alphabetical (with another text input custom field named city).
the only difference in my test is that i didn’t test with the same post_type, let me know if you still having issues.
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.