WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#8861 closed enhancement (invalid)

get_tag_link only works for post_tag

Reported by: olivM Owned by: ryan
Milestone: Priority: normal
Severity: normal Version: 2.7
Component: Taxonomy Keywords: taxonomy link
Focuses: Cc:

Description

the get_tag_link function only works for the post_tag taxonomy.

so perhaps we should have get_tag_link( $tag_id, $taxonomy ) or get_term_link( $term_id, $taxonomy )

which should look like this :

function get_tag_link( $tag_id, $taxonomy = 'post_tag' ) {
	global $wp_rewrite;
	$taglink = $wp_rewrite->get_extra_permastruct($taxonomy);
	
	$tag = &get_term( $tag_id, $taxonomy );
	if ( is_wp_error( $tag ) )
		return $tag;
	$slug = $tag->slug;

	if ( empty( $taglink ) ) {
		$file = get_option( 'home' ) . '/';
		$taglink = $file . '?'.$taxonomy.'=' . $slug;
	} else {
		$taglink = str_replace( '%'.$taxonomy.'%', $slug, $taglink );
		$taglink = get_option( 'home' ) . user_trailingslashit( $taglink, 'category' );
	}
	return apply_filters( 'tag_link', $taglink, $tag_id );
}

Change History (1)

comment:1 @ryan6 years ago

  • Milestone 2.8 deleted
  • Resolution set to invalid
  • Status changed from new to closed

We do have get_term_link().

Note: See TracTickets for help on using tickets.