How to use wp_get_recent_posts with many post types?

I’ve tried displaying many post types (separated by comma) and it didn’t work. Is there a way to achieve this?

$args = array( 'numberposts' => '5', 'post_type' => 'cpt1, cpt2, cptn');
    $recent_posts = wp_get_recent_posts( $args );

Thanks for your input.

1 Answer
1

Use post types as an array.

$args = array( 
    'numberposts' => '5', 
    'post_type'   => array('cpt1', 'cpt2', 'cptn') 
);
$recent_posts = wp_get_recent_posts( $args );

Leave a Comment