2

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; ?>
3
  • Friend, while statement should contain while {}. Commented Mar 28, 2015 at 5:45
  • @abdulla Sorry, could you give me an example of the proper way to implement? Commented Mar 28, 2015 at 5:57
  • codex.wordpress.org/The_Loop Commented Mar 28, 2015 at 6:10

1 Answer 1

3

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', ), 
);
Sign up to request clarification or add additional context in comments.

1 Comment

Ah, ok. That makes perfect sense. Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.