I need some help writing a shortcode to display all product tags associated with a specific product category which can be displayed on any page.
My problem is that I can display all product tags anywhere by using the below code, but I'm unable to filter those tags by a given product category:
function product_terms_by_cat() {
$terms = get_terms (
array (
'taxonomy' => 'product_tag',
'hide_empty' => false)
);
foreach ( $terms as $term ) {
echo $term->name;
}
}
add_shortcode('product_terms_by_cat', 'product_terms_by_cat');
I've tried using functions for standard WP post tags/categories but they're used within the loop (eg. category pages or single post pages) and don't help.
Could modifying the code found on this link work?The code filters categories based on tags (the opposite of what I want). Cheers