How to Query Blog Post By Custom Taxonomy Added from URL
Learn how to query custom taxonomy in WordPress. This script was used to query custom taxonomy in the tag.php template
<h2>Portfolio Items Using this Tag</h2>
<?php
$tag = get_queried_object();
$args = array(
'post_type' => 'portfolio',
'tax_query' => array(
array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => $tag->slug,
),
)
);
$all_posts = new WP_Query($args);
while ($all_posts -> have_posts()) : $all_posts -> the_post();
the_title();
endwhile;
wp_reset_postdata();
?>