Ok, found the answer! I added 'query_id'
parameter in my query
$query_string = sanitize_text_field( wp_unslash( $_GET['searchString'] ) );
$page_no = intval( $_GET['pageNo'] );
$posts_per_page = 9;
$offset = ( $page_no - 1 ) * $posts_per_page;
$search_args = array(
'posts_per_page' => $posts_per_page,
'post_status' => 'publish',
'perm' => 'readable',
's' => $query_string,
'offset' => $offset,
'query_id' => 'my_custom_ajax_search',
);
$search_results = new WP_Query( $search_args );
After that in my filter
add_filter( 'posts_orderby', 'my_order_search_by_posttype', 10, 2 );
function my_order_search_by_posttype( $orderby, $wp_query ) {
if ( ! is_admin() && ( is_search() || isset( $wp_query->query['query_id'] ) && $wp_query->query['query_id'] === 'my_custom_ajax_search' ) ) {
...
}
}
And it works! đ