'Returning wp posts that match a given taxonomy entry within a custom post type
I'm having trouble in dynamically displaying given post entries according to a post category.
I have a custom post type - specialisms, within which there are a number of custom fields.
One of the fields for each specialism is a taxonomy (created underneath the Specialisms CPT), Sectors, with three options, Data, Saas and EPM.
For a 'Sector' page template, I'm attempting to create a loop that uses tax_query to show the Specialism posts that match the title / slug of that sector page.
Eg. if there's a page for Data, then on the page it will show the Specialisms posts which have 'Data' as the taxonomy entry.
This is my attempted loop... Where using 'data' shows me the right articles, but I can't seem to dynamically place the Sector name in place of 'data' (I'm sure I'm missing something obvious here)
Hugely grateful of any assistance...
<?php
$loop = new WP_Query([
'post_type' => 'specialisms',
'tax_query' => [
[
'taxonomy' => 'sectors',
'field' => 'slug',
'terms' => 'data'
],
],
]);
while ($loop->have_posts()) : $loop->the_post();
//prePrint($loop);
{
?>
<a href="<?php the_permalink() ?>">
<h3><?php the_title(); ?></h3>
</a>
<?php
}
endwhile; ?>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
