WP_Query and DES sort for Custom Taxonomy based upon a meta field?

Nothing. You shouldn’t need to set the post type. Your taxonomy archive is presumably already querying the correct post type.

function customize_customtaxonomy_archive_display ( $query ) {
    if ( $query->is_tax( 'country' ) ) {
        $query->set( 'meta_key', 'start_date' );
        $query->set( 'orderby', 'meta_value_num' );
        $query->set( 'order', 'ASC' );
    }
}

Note:

  • $query->is_main_query() is redundant when checking $query->is_tax(), because (as far as I’m aware) secondary queries can never be a taxonomy archive.
  • Setting the posts per page has nothing to do with sorting, so I’ve omitted it.
  • You need to use {} with if statements, otherwise the condition will only apply to the next line. The original code you’ve copied will apply that sorting and posts per page value to all queries. Even if you only have one line, omitting the brackets is considered poor practice.

tech