I'm writing Wordpress page template that will get the page slug and use a WP_query to make a list of all posts with tag=page slug. My code doesn't throw up any errors but rather gives me an empty list, when there are definitely posts with the appropriate tag.
Code:
<?php
$tag = $post -> post_name;
$query = new WP_Query('tag = $tag');
while ($query -> have_posts()) {
$query -> the_post();
echo '<li>' . get_the_title() . '</li>';
}
?>
I'm using a local version of Wordpress 4.0.1 on Mac, Yosemite.
Any advice would be much appreciated,
Cheers!