Home › Forums › General Issues › How can the following wp query be sorted by a custom field? › Reply To: How can the following wp query be sorted by a custom field?
Thank you so much!!! Now it is working great!!!!
There’s only a detail missing: If I have more than one post with the same category. For example two posts with the contact region value as Santiago, the two are displayed instead of only one. Each region has a category assigned to it while “Contact Data”” is the parent category of all of them.
code I’m using:
$news_cat_ID = get_cat_ID( 'Contact Data' );
$news_query = new WP_Query( array(
'posts_per_page' => -1,
'cat' => $news_cat_ID,
'no_found_rows' => true,
'ignore_sticky_posts' => true,
'meta_key' => 'region_contacto',
'orderby' => array( 'meta_value' => 'ASC', 'modified' => 'DESC' )
));
?>
<?php while ( $news_query->have_posts() ) : $news_query->the_post() ?>
Edit: deleted this line as well:
$news_cats = get_categories( “parent=$news_cat_ID” );
And added a bit more of info.
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.