Skip to main content
1 of 7
birgire
  • 67.8k
  • 7
  • 119
  • 251

It looks like WP_Comment_Query() only supports a single post type.

You can adjust it, by using the comments_clauses filter.

Try for example:

$defaults = array(
    'number' => 5,
    'post_type' => 'post'
);
add_filter( 'comments_clauses', 'wpse_121051');     
$comments = get_comments($defaults)

where

 /**
  * Support for multiple post types for comments
  *
  * @param array $clauses
  * @return array $clauses
  */   
 function wpse_121051( $clauses )
 {
    global $wpdb;
    
    // Adjust this to your likings:
    $old_post_type  = 'post';
    $new_post_types = array( 'post', 'authors', 'movies' );  

    // Remove our 'comments_clauses' filter, since we don't need it anymore
    remove_filter( current_filter(), __FUNCTION__ );

    // Add support for multiple post types
    $from = "$wpdb->posts.post_type = '" . $old_post_type . "'";
    $to   = "$wpdb->posts.post_type IN ( '" . join( "', '", $new_post_types ) . "' ) ";
    $clauses['where'] = str_replace( $from, $to, $clauses['where'] );

    return $clauses;
 }
birgire
  • 67.8k
  • 7
  • 119
  • 251