Support

Account

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..