Make WordPress Core


Ignore:
Timestamp:
05/23/2015 06:28:22 PM (9 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r32498 r32553  
    43824382 *
    43834383 * @since 2.5.0
     4384 * @since 4.3.0 Introduced `$field` argument.
    43844385 *
    43854386 * @param object|int|string $term     The term object, ID, or slug whose link will be retrieved.
    43864387 * @param string            $taxonomy Optional. Taxonomy. Default empty.
     4388 * @param string            $field    Optional. The term field that should be matched by the `$term` argument. Accepts
     4389 *                                    any `$field` values accepted by `get_term_by()`: 'slug', 'name',
     4390 *                                    'term_taxonomy_id', or 'id'. Default is 'slug', unless `$term` is an integer, in
     4391 *                                    which case it's asssumed to be an ID.
    43874392 * @return string|WP_Error HTML link to taxonomy term archive on success, WP_Error if term does not exist.
    43884393 */
    4389 function get_term_link( $term, $taxonomy = '' ) {
     4394function get_term_link( $term, $taxonomy = '', $field = null ) {
    43904395    global $wp_rewrite;
    43914396
    43924397    if ( !is_object($term) ) {
    4393         if ( is_int($term) ) {
    4394             $term = get_term($term, $taxonomy);
    4395         } else {
    4396             $term = get_term_by('slug', $term, $taxonomy);
    4397         }
     4398        if ( is_null( $field ) ) {
     4399            $field = is_int( $term ) ? 'id' : 'slug';
     4400        }
     4401
     4402        $term = get_term_by( $field, $term, $taxonomy );
    43984403    }
    43994404
Note: See TracChangeset for help on using the changeset viewer.