WordPress.org

Ready to get started?Download WordPress

Forums

Retrieve Custom Taxonomy Rewrite Slug (3 posts)

  1. Justin Sternberg
    Member
    Posted 3 years ago #

    I'm looking to retrieve the custom taxonomy slug (or permalink) to use as a way to list all the terms in my custom taxonomy with links to their archive pages. Here is the code i have:

    $taxonomyname = get_query_var('taxonomy');
    		echo '<h3>All ' . $taxonomyname .'</h3><br/>';
    		$terms = get_terms($taxonomyname);
    		echo "<ul>";
    		foreach ($terms as $term) {
    			echo "<li><a href='". site_url('/favorite-foods/','')  .$term->slug. "'>" .$term->name. "</a></li>";
    		}
    		echo "</ul>";

    the part that says
    <a href='". site_url('/favorite-foods/','') .$term->slug. "'>" .$term->name. "</a>
    i would like to replace with something like this:
    <a href='". site_url() . $my-custom-taxonomy-rewrite-slug . $term->slug . "'>" .$term->name. "</a>

    If anyone can point me in the right direction, i would be much obliged!

  2. Mark Barnes
    Member
    Posted 3 years ago #

    You've probably fixed it by now, but in case anyone else comes across this problem, you need to declare $wp_post_types as global and then use $wp_post_types[$post_type]->rewrite['slug'].

  3. tj2point0
    Member
    Posted 2 years ago #

    I think a plugin, Taxonomic SEO Permalink can solve your problem. I created this plugin because I wanted to use custom taxonomies in permalink just like we do with %category% or %tag%.

    Recently I added support for sub-taxonomy which might not be a perfect solution but it solved problem of sub-taxonomy by a fix.

Topic Closed

This topic has been closed to new replies.

About this Topic