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?

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