The following code works with my custom post type “game”:
function ptc_customize_wp_query( $query ) {
if ( $query->is_post_type_archive( 'game' ) ) {
// Sort portfolio posts by project start date.
$query->set( 'order', 'DESC' );
$query->set( 'orderby', 'meta_value_num' );
// ACF date field value is stored like 20220328 (YYYYMMDD).
$query->set( 'meta_key', 'release-date' );
}
}
But my custom posts “Game” also have custom taxonomies like “genre”. How can I apply this sorting to these custom taxonomies as well?
You cannot order terms by a custom field. You have to build your own sorting mechanism. My first suggestion is going to be doing a web search for “wordpress order terms by custom field”