I managed to force it:
i first assigned a custom class to the body_class of the page i wanted to modify and then i used the function using the conditional tag to check if it was a category and that specific class
lascio il codice se fosse utile per qualcuno
function add_body_class_for_page_id( $classes ) {
global $post;
if ( isset( $post->ID ) && $post->ID == 3383 ) {
$classes[] = ‘custom-class’;
}
return $classes;
}
add_filter( ‘body_class’, ‘add_body_class_for_page_id’ );
add_filter( ‘pre_get_posts’, ‘custom_get_posts’ );
function custom_get_posts( $query ) {
if( is_category() && in_array( ‘custom-class’, get_body_class() ) ) {
$query->set( ‘orderby’, ‘name’ );
$query->set( ‘order’, ‘ASC’ );
}
return $query;
}
add_filter( ‘pre_get_posts’, ‘custom_get_posts’ );
function custom_get_posts( $query ) {
if( is_category() || is_archive() ) {
$query->set( ‘orderby’, ‘name’ );
$query->set( ‘order’, ‘ASC’ );
}
return $query;
}