So pretty straightforward, seemingly, but I can’t find any examples in either a) the WordPress Codex; or b) in any examples in the wild. I’m just trying to exclude a term from this output of terms from a custom taxonomy.
I went with wp_get_object_terms instead of get_terms because I have the output needs to be formatted specifically and it seems wp_get_object_terms is the only function that can do the job, although get_terms do have an explicit ‘exclude’ option. So here’s what I’m working with:
<?php $taxopostid = $post->ID;
$taxoquery = wp_get_object_terms( $taxopostid, 'work-type');
$taxoslug = $taxoquery[0]->slug;
$taxotitle = $taxoquery[0]->name; ?>
<a href="<?php bloginfo('url'); ?>/blog-slug/<?php echo $taxoslug; ?>/" class="cat-link"><?php echo $taxotitle; ?></a>
Any ideas??
I’m going to assume
worktype
is the taxonomy you want to exclude.Step 1
Get all taxonomies excluding
worktype
withget_terms()
(you know how to do this right?)Step 2
With the result make a flat array only containing all the fetched taxonomies (lets call it
$allTaxonomiesExcludingWorkType
)Step 3
Add the array as the second argument to
wp_get_object_terms($taxopostid, $allTaxonomiesExcludingWorkType);
Not tested but this should help you on your way.
GL