the solution is given in your error itself "use the WP_Query->is_main_query() method"
–
try this –
if($query->is_main_query() && !empty($selected_sort_types) && empty($orderby)) {
$_sort_types = array_keys($selected_sort_types);
$orderby = $_sort_types[0];
$query->set('orderby', $orderby);
}
instead of this –
if(is_main_query() && !empty($selected_sort_types) && empty($orderby)) {
$_sort_types = array_keys($selected_sort_types);
$orderby = $_sort_types[0];
$query->set('orderby', $orderby);
}
2
solved Notice: is_main_query was called incorrectly