-1

Anyone can help with this please? It's driving me crazy.

I have 2 taxonomies on my website, the built-in categories and one I created called Countries ('country'). I want to order all the posts that lead to custom taxonomy by title and keep the posts that lead to built-in categories in order by date.

I am using the following code, but it gives me posts on both taxonomies ordered by title. What I am doing wrong?

add_action( 'pre_get_posts', 'theme_taxonomy_order' );
function domino_taxonomy_order($query){
    if(!$query->is_main_query()) return $query;
    if(is_country) $query->set( 'orderby', 'title' );
    if(is_country) $query->set( 'order', 'ASC' );
    return $query;
}

1 Answers1

0

I made it work eventually! That's the correct code:

//Customise Country taxonomy archive display
add_action( 'pre_get_posts', 'customise_country_taxonomy_archive_display' );
function customise_country_taxonomy_archive_display ( $query ) {
    if (($query->is_main_query()) && (is_tax('country'))){
    $query->set( 'orderby', 'title' );
    $query->set( 'order', 'ASC' );
}
}