I have a custom post type of countries. On the individual 'country' page I want to display a loop of another custom post type ('Itineraries') where the itineraries items are tagged with the same name as the country title. E.g. I want all Itinerary items tagged with the word 'Peru' to appear on the 'Peru' country page.
I have tried the following code which works if I hard code a country name e.g. 'Peru' . However I want to dynamically populate this with the country title of each page. I have tried replacing 'tag' => 'peru' with 'tag'=> $country_title but am not sure of the syntax. Thanks for any help.
<?php
$country_title = get_the_title();
//echo $country_title;
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'itinerary', //Specifying post type
'posts_per_page' => 10, //How many posts per page
// 'cat' =>'cat2', //Specifying post category to show posts
'tag' =>'peru',
'paged' => $paged //For pagingation (if required)
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
xxxxxx
<?php
endwhile; ?>