最可靠的方法是定义自己的查询变量,然后进行检查:
$my_query = new WP_Query( array(
...
\'context\' => \'my_query\'
) );
然后,从您的回调中:
function alter_post_clauses( $clauses, $wp_query ) {
if ( \'my_query\' == $wp_query->get( \'context\' ) ) {
// do stuff
}
return $clauses;
}
add_filter( \'posts_clauses\', \'alter_post_clauses\', 10, 2 );