看起来像是WP_Comment_Query()
仅支持单个立柱类型。
您可以使用comments_clauses
滤器
请尝试以下示例:
$defaults = array(
\'number\' => 5,
\'post_type\' => array( \'post\',\'authors\',\'movies\' ),
);
add_filter( \'comments_clauses\', \'wpse_121051\', 10, 2 );
$comments = get_comments($defaults)
在哪里
/**
* Support for multiple post types for comments
*
* @param array $clauses
* @param object $wpqc WP_Comment_Query
* @return array $clauses
*/
function wpse_121051( $clauses, $wpqc )
{
global $wpdb;
// Remove the comments_clauses filter, we don\'t need it anymore.
remove_filter( current_filter(), __FUNCTION__ );
// Add the multiple post type support.
if( isset( $wpqc->query_vars[\'post_type\'][0] ) )
{
$join = join( "\', \'", array_map( \'esc_sql\', $wpqc->query_vars[\'post_type\'] ) );
$from = "$wpdb->posts.post_type = \'" . $wpqc->query_vars[\'post_type\'][0] . "\'";
$to = sprintf( "$wpdb->posts.post_type IN ( \'%s\' ) ", $join );
$clauses[\'where\'] = str_replace( $from, $to, $clauses[\'where\'] );
}
return $clauses;
}
插件:正如@kaiser善意的建议,我做了一个
small plugin 将多个帖子类型支持添加到
WP_Comment_Query()
和
get_comments()
. 希望WordPress核心在不久的将来能够支持这个缺失的功能;-)