WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 9 months ago

Last modified 9 months ago

#17652 closed defect (bug) (duplicate)

get_term_link doesn't accept $term->term_id without explicit casting as numeric

Reported by: tomauger Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.1.3
Component: Taxonomy Keywords:
Focuses: Cc:

Description

global $wp_query;

$term = $wp_query->get_queried_object();

get_term_link($term, $term->taxonomy); ok

get_term_link($term->slug, $term->taxonomy); ok

get_term_link($term->term_id, $term->taxonomy); WP_Error ('Empty Term')

echo ($term->term_id); ok (echoes correct ID)

Change History (7)

comment:1 tomauger3 years ago

  • Summary changed from get_term_link doesn't accept term_ID to get_term_link doesn't accept $term->term_id without explicit casting as numeric

get_term_link(intval($term->term_id), $term->taxonomy); ok

comment:2 dd323 years ago

This is due to get_term() and get_term_by() not int'ing the fields when using a raw context. See http://core.trac.wordpress.org/ticket/17646#comment:5 for a patch which sanitizes them.

See also #16469 (This and that can probably be closed as a duplicate of either #17646 or one of the other int'ing tickets)

comment:3 jonathanwold2 years ago

  • Cc jonathanwold added
  • Version changed from 3.1.3 to 3.3.1

I ran into this today trying to get the link using the term_id. The codex (http://codex.wordpress.org/Function_Reference/get_term_link) specifies that term_id can be used. Should I update it to reflect that there is a bug or just hold tight until the bug is fixed?

comment:4 DrewAPicture2 years ago

  • Version changed from 3.3.1 to 3.1.3

The version field is used to track when a bug was first reported.

comment:5 eddiemoya12 months ago

  • Cc eddie.moya+wptrac@… added

comment:6 ericmann9 months ago

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #17646.

comment:7 dd329 months ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.