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?
Another try based on
https://make.wordpress.org/core/2014/08/29/a-more-powerful-order-by-in-wordpress-4-0/
<?php
$news_cat_ID = get_cat_ID( 'Datos de Contacto' );
$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' => array( 'meta_value_num' => 'ASC', 'modified' => 'DESC' )
));
?>
<?php while ( $news_query->have_posts() ) : $news_query->the_post() ?>
Not sure what to try next..
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.