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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.