In order to have posts in ascending order in a specific category, I inserted the following string in function file:
function reverse_order($query) {
if(!is_admin() && $query->is_main_query() && ($query->is_category(314) || cat_is_ancestor_of(314,get_category_by_slug( $query->get( 'category_name' ))))) {
$query->set('order','ASC');
}
}
add_action('pre_get_posts', 'reverse_order');
Everything would seem to work, except that every seven minutes, in error.log is notified the following problem, of which therefore, I’d like to understand the solution:
PHP Warning: Attempt to read property "term_id" on null in /home/*****/public_html/wp-includes/class-wp-query.php on line 3761
PHP Warning: Attempt to read property "name" on null in /home/*****/public_html/wp-includes/class-wp-query.php on line 3763
PHP Warning: Attempt to read property "slug" on null in /home/*****/public_html/wp-includes/class-wp-query.php on line 3765
The strings involved are consequently these:
$cat_obj = $this->get_queried_object();
$category = array_map( 'strval', (array) $category );
if ( in_array( (string) $cat_obj->term_id, $category, true ) ) {
return true;
} elseif ( in_array( $cat_obj->name, $category, true ) ) {
return true;
} elseif ( in_array( $cat_obj->slug, $category, true ) ) {
return true;
}
return false;
}
Thanks in advance