Reputation: 49
I have a custom post type with two taxonomies, project-type and project-name. I am trying to display a list of project-names with links when the project-type is photography. The code I have so far is
<?php
if(is_taxonomy('photography'))
{
$taxonomy = 'project-name';
$tax_terms = get_terms($taxonomy);
?>
<ul>
<?php
foreach ($tax_terms as $tax_term)
{
echo '<li>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a></li>';
}
}
?>
</ul>
If I remove the if then it displays all the project-names but I need it to show only the ones that also have the project-type 'photography'.
Any help would be much appreciated.
Upvotes: 0
Views: 155
Reputation: 3629
Check this...
$term = get_term_by('name', 'photography', 'project-type');
if($term != false ){
$taxonomy = 'project-name';
$tax_terms = get_terms($taxonomy);
?>
<ul>
<?php
foreach ($tax_terms as $tax_term)
{
echo '<li>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a></li>';
}
?>
</ul>
<?php
}
I hope this is what you wanted...
Upvotes: 1