Wordpress - get term archive url / link

Use get_term_link

e.g. to print out a list of actors terms linking to the archives:

$terms = get_terms('actors');
echo '<ul>';
foreach ($terms as $term) {
    echo '<li><a href="'.get_term_link($term).'">'.$term->name.'</a></li>';
}
echo '</ul>';

However!

If what you really mean is the equivilant of the custom post type archive, that lists all the posts of that type, but for taxonomy terms, e.g. a page that acts as an archive listing the various taxonomy terms available, then you're out of luck. There are no taxonomy archives in WordPress for terms, only posts assigned to a given term.

To produce a page listing the taxonomy terms you can use code similar to the above. Then put it in a page template and use that page as your taxonomy term archive.

The reason why is that the problem lies in the post loop, almost every single page template is intended to have one, and if you look at the template heirarchy, if the necessary templates aren't found, it all goes back to index.php, and index.php has a post loop that displays posts, not a term loop. This and the many different ways and ideas of how terms should be listed means there is no consensus. What about date archives? Should there be an archive listing months and years? Timelines? Panels tiles clouds etc


There is no simple way to get this from scouring. And everyone who answers everywhere thinks you want to link to a TERM in the TAXONOMY... While you're looking to get a link to the TAXONOMY archive... For which I have found absolutely nothing.

Basically, like many people, you want a get_taxonomy_archive_link method.

Except, for one reason or another, it simply does not exist. I consider this a MAJOR failure on Wordpress's side.

There is no answer to your question. Not one that actually works within the WP framework as a proper solution. Sure, you can piece together get_bloginfo() for your needs, but there is absolutely no logical reason within WP that get_taxonomy_archive_link doesn't exist.

That all being said, I always add the following function to my themes:

/**
 * Pass in a taxonomy value that is supported by WP's `get_taxonomy`
 * and you will get back the url to the archive view.
 * @param $taxonomy string|int
 * @return string
 */
function get_taxonomy_archive_link( $taxonomy ) {
  $tax = get_taxonomy( $taxonomy ) ;
  return get_bloginfo( 'url' ) . '/' . $tax->rewrite['slug'];
}

it seems that you're asking for a link to an archive with "all posts which has any term from the taxonomy Actors". everyone here replied as if you asked for the link to a specific term archive because what you're asking doesn't make sense in the wordpress world.

I am surprised by the answer of pixelbacon and the fact that it has 6 upvotes... That function returns an url which leads nowhere... wordpress doesn't have a way to interpret that url nor to make the query which would have to be behind that request.

in the database a Taxonomy has relations with the terms, and the terms have relations with the posts. A single post doesn't have relations with the taxonomy. The only thing that connect them is the fact that a post-type could support a Taxonomy.

Let's write down in words what you're trying to display in that page: "Show me all the posts of the post_type 'post', which has ANY term from the taxonomy Actors."

this basically translate to: "show me all posts of the post_type 'post' (which supports the taxonomy Actors)".

Therefore the only difference from a general post_type archive (show all posts from a given post_type) would be IF you have posts which don't have any Actor term assigned and you DO want to exclude them.

If that's the case, then you can create a custom page, make a generic query to all posts, then in the loop you check if the post has any Actors term with wp_get_post_terms(get_the_ID(), 'actors'), and eventually exclude it if doesn't have any.