I am trying to do a WP_Query where I want the loop to execute only if the post type is books and genre is the text in $genre. I keep getting an error as it displays all the posts in the books post type instead of the particular genre required.
I have tried this:
<?php
$genre ="suspense";
$args = array('post_type' => 'books','genre' => $genre);
//Define the loop based on arguments
$loop = new WP_Query( $args );
//Display the contents
while ( $loop->have_posts() ) : $loop->the_post();
?>