您可以尝试使用comments_clauses
过滤器:
$args = array( \'user_id\' => 0 );
add_filter( \'comments_clauses\', \'custom_comments_clauses\');
$comments = get_comments( $args );
remove_filter( \'comments_clauses\', \'custom_comments_clauses\');
function custom_comments_clauses( $clauses ){
$clauses[\'where\'] = str_replace( \'user_id = 0\', \'user_id IN (1, 2, 3)\', $clauses[\'where\'] );
return $clauses;
}
更新:您还可以添加自定义参数,
my_user_ids
, 对于这样的查询:
$args = array( \'user_id\' => 0, \'my_user_ids\' => array(1,2,3) );
add_filter( \'comments_clauses\', \'custom_comments_clauses\', 99, 2 );
$comments = get_comments( $args );
remove_filter( \'comments_clauses\', \'custom_comments_clauses\', 99, 2 );
function custom_comments_clauses( $clauses, $query ){
if( isset( $query->query_vars[\'user_id\'] ) && isset( $query->query_vars[\'my_user_ids\'] ) ){
$user_id = $query->query_vars[\'user_id\'];
$user_ids = $query->query_vars[\'my_user_ids\'];
if( count( $user_ids ) > 0 ){
$from = sprintf( \'user_id = %d\', $user_id );
$to = sprintf( \'user_id IN (%s)\', join( \',\', $user_ids ) );
$clauses[\'where\'] = str_replace( $from, $to, $clauses[\'where\'] );
}
}
return $clauses;
}
在哪里
$my_user_ids
是用户ID的数组。