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?
I just noticed an error in the code that you posted.
try this:
<?php
$news_cat_ID = get_cat_ID( 'Contact Data' );
$news_cats = get_categories( "parent=$news_cat_ID" );
foreach ( $news_cats as $news_cat ) :
$news_query = new WP_Query( array(
'cat' => $news_cat->term_id,
'posts_per_page' => 1,
'no_found_rows' => true,
'ignore_sticky_posts' => true,
'meta_key' => 'region_contacto',
'orderby' => 'meta_value',
'order' => 'ASC',
));
?>
<?php while ( $news_query->have_posts() ) : $news_query->the_post() ?>
//Code in the loop
<?php endwhile ?>
<?php endforeach ?>
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.