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?

  • 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 ?>