How to loop through multiple custom post types?

I’m unable to get this wordpress loop to work: I’m trying to get it to display two post types, the slugs are ‘movie’ and ‘tvshow’.

Not sure what I’m doing wrong here – It’s displaying whichever post type I put first after the =>, and they both work by themselves.

<?php 
$movieArg = array('post_type' => 'movie', 'tvshow');
$query = new WP_Query($movieArg);
while($query -> have_posts()) : $query -> the_post();
?>


<div class="movie">

<h2><?php the_title(); ?> </h2>

</div>


<?php endwhile; ?>

Related posts

Leave a Reply

1 comment

  1. There’s an issue with the way you’re specifying multiple post types.

    They need to be listed inside an array. Right now you’re setting the post type to movie while tvshow is another element in the main array.

    Change this:

    $movieArg = array('post_type' => 'movie', 'tvshow');
    

    To:

    $movieArg = array(
        'post_type' => array( 'movie', 'tvshow', ), 
    );