[wp-trac] [WordPress Trac] #16469: Cannot pass in ID for get_term_link() if using custom taxonomy

WordPress Trac wp-trac at lists.automattic.com
Mon Mar 7 08:02:36 UTC 2011


#16469: Cannot pass in ID for get_term_link() if using custom taxonomy
--------------------------+------------------------------
 Reporter:  sparkweb      |       Owner:
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Taxonomy      |     Version:  3.0.4
 Severity:  normal        |  Resolution:
 Keywords:                |
--------------------------+------------------------------

Comment (by dd32):

 Replying to [comment:14 mikeschinkel]:
 > Replying to [comment:11 dd32]:
 > > If someone passes a (string)'1' in as the term_id, they're doing it
 wrong, OR an API call is returning the data in the incorrect format.
 >
 > For the record, my example showing `'1'` was for simplicity of example;
 my use-cases have been being returned as a string from something else,
 like `$_GET['term_id']`.
 >
 > > The correct fix here, is to verify that ALL term objects being
 returned return the term_id as a integer, that'll fix most of these
 casting problems (ie. It may return a string '1' instead of (int)1)
 >
 > WordPress can't force `$_GET['term_id']` to return a numeric.  Sure the
 developer can cast it as `(int)`, but they have to know that it needs to
 be cast; hence the crux of the problem.

 Well no, Because that's not a term object is it? It's your data, as a
 plugin developer it's your responsibility to pass the correct parameters
 to functions. The documentation *may* (I havn't read it) may need to
 stress the fact it requires a integer value to be passed, not a numeric
 string.

 Upon reading some of the documentation:
  * get_term(): ` * @param int|object $term If integer, will get from
 database. If object will apply filters and return $term.`
  * get_term_link(): `* @param object|int|string $term`

 In both cases you need to read the documentation, and then possibly read
 the first few lines of the function if you're not used to "int" meaning a
 literal integer..

 Simple fact here, Is that the function cannot change to accept a numerical
 string for ID lookups, nor can any of the Taxonomy API's which accept
 multiple data types be changed to accept numerical strings (those which
 only take int's seem to all cast them appropriately). so ultimately, the
 only change needed here is better education, through more documentation or
 more forceful hints as to the datatypes.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/16469#comment:15>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list