Get Custom URL For Custom Taxonomy
-
‘ve got a custom post type called productpopups, and to sort them I have a custom taxonomy called productcategory. The post type has it’s own special template (single-productpopup.php) and I’m trying to show each products category with a link to the category. The problem I have is the following:
The link for each productcategory is say
example.com/productcategory/category
but the page I want to link it to is actuallyexample.com/category
So I made up this:
<p>Categories: <?php $categories = get_the_terms( $post->ID, 'productcategory' ); foreach( $categories as $category ) { echo '<a href="https://example.com/'.$category->slug.'">'.$category->name.'</a>, '; } ?> </p>
This works because the pages I have set up use the same slugs as the
productcategory
, but its hacky and one slip (like a typo) will break it.What I’d essential like to do is add a custom field to the taxonomy where I can specify the page url, and then be able to call that instead of the
https://example.com/.$category->slug
Is this possible?
- The topic ‘Get Custom URL For Custom Taxonomy’ is closed to new replies.