WordPress.org

Make WordPress Core

Opened 10 years ago

Closed 5 years ago

#14156 closed enhancement (wontfix)

Option to use name, in additon to slug and id in get_term_link() function

Reported by: sudar Owned by: boonebgorges
Milestone: Priority: low
Severity: normal Version: 3.0
Component: Taxonomy Keywords: 2nd-opinion
Focuses: Cc:

Description

Right now the get_term_link() function (in wp-includes/taxonomy.php) can be used only with either term id or term slug.

It would be useful to provide an option to add name in addition to term id and slug.

This function inturn uses get_term_by() function and it has the option to provide term name, but the get_term_link() function doesn't have a way to do this.

Attachments (3)

get_term_link.patch (721 bytes) - added by sudar 10 years ago.
Path which adds the third parameter to get_term_link function
14156.patch (956 bytes) - added by mordauk 5 years ago.
14156-tests.patch (1.1 KB) - added by mordauk 5 years ago.

Download all attachments as: .zip

Change History (22)

@sudar
10 years ago

Path which adds the third parameter to get_term_link function

#1 @sudar
10 years ago

  • Keywords has-patch added

#2 @scribu
10 years ago

  • Milestone changed from Awaiting Review to 3.1
  • Priority changed from normal to low

+1 on the idea.

#3 @scribu
10 years ago

On the other hand, while I agree that:

get_term_link( 'Term Name', 'taxname', 'name' )

looks better than:

get_term_link( get_term_by( 'name', 'Term Name', 'taxname' ), 'taxname' )

, it's just an implementation detail. get_term_link() shouldn't be concerned with retrieving the correct term.

To avoid passing the taxonomy over and over again, it would be nice if you could do something like this instead:

get_term_by( 'name', 'Term Name', 'taxname' )->get_link()

#4 @scribu
10 years ago

Related: #14162.

#5 @scribu
10 years ago

Related: #13081.

#6 @markjaquith
9 years ago

  • Milestone changed from 3.1 to Future Release

To late for enhancements for 3.1.

#7 @wonderboymusic
7 years ago

  • Keywords needs-refresh added; taxonomy get_term_link removed

#8 @boonebgorges
5 years ago

  • Keywords needs-unit-tests added

@mordauk
5 years ago

@mordauk
5 years ago

#9 @mordauk
5 years ago

  • Keywords needs-refresh needs-unit-tests removed

14156.patch refreshes the patch.

14156-tests.patch adds unit tests.

#10 @boonebgorges
5 years ago

In 32552:

Unit tests for get_term_link().

See #14156.

#11 @boonebgorges
5 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 32553:

Introduced $field argument to get_term_link().

This new argument allows developers to specify which term field should be
matched by the value of the $term parameter (in particular, 'name' and
'term_taxonomy_id' are now supported).

Props sudar, mordauk.
Fixes #14156.

#12 @SergeyBiryukov
5 years ago

  • Milestone changed from Future Release to 4.3

#13 follow-up: @johnbillion
5 years ago

  • Keywords 2nd-opinion added; has-patch removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

I'm a little concerned that this introduces yet more inconsistency with regard to which term functions accept which values for their $term argument. This is now the only term function apart from get_term_by() which accepts a $field argument.

Should we add the $field parameter to get_term_feed_link(), get_edit_term_link() or other term functions too?

#14 in reply to: ↑ 13 @sudar
5 years ago

Replying to johnbillion:

Should we add the $field parameter to get_term_feed_link(), get_edit_term_link() or other term functions too?

I can send a new patch for this with $field parameter for both the functions if we decided to do it.

This ticket was mentioned in Slack in #core by helen. View the logs.


5 years ago

#16 @helen
5 years ago

I'm leaning toward reverting this - I'm not completely sure in what scenario you only have the term name available to you, and doing a get_term_by() first yourself is more correct than mixing this into get_term_link() IMO. I'd way rather get on a WP_Term object, see #14162 for that.

#17 @boonebgorges
5 years ago

I don't feel strongly about it. I agree that it introduces some inconsistency in function interfaces, and I agree that the workaround (looking up a term with get_term_by() before fetching the term link) is far from onerous. Let's revert.

#18 @boonebgorges
5 years ago

In 33022:

Don't allow $field param to be passed to get_term_link().

The new parameter creates inconsistencies in the signatures of the various
functions for fetching term links (get_term_feed_link(),
get_edit_term_link(), etc.).

Reverts [32553].

See #14156.

#19 @boonebgorges
5 years ago

  • Milestone 4.3 deleted
  • Resolution set to wontfix
  • Status changed from reopened to closed
Note: See TracTickets for help on using tickets.