好的,找到答案了!我补充道\'query_id\'
我的查询中的参数
$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 );
之后在我的过滤器中
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\' ) ) {
...
}
}
而且很有效!:)