I want to retrieve custom post title by tag name.I have tag name and i want to retrieve title.How can i do this.
<?php
$tagname=get_post_meta(get_post()->ID, 'campaign_tag', true);
echo $tagname;
$args = array(
'post_type' => 'campaign',
'posts_per_page' => 20,
'tag' => $tagname,
);
$query = new WP_Query($args);
while($query -> have_posts()) : $query -> the_post();
?>
<h5><?php the_title(); ?></h5>
<?php endwhile; wp_reset_query();
?>
For CPT (custom post type) You should use tax_query.
Like that:
Refer: https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters