[wp-trac] [WordPress Trac] #18636: is_tax() returns false when is_category() or is_tag() returns true
WordPress Trac
noreply at wordpress.org
Tue Dec 4 21:31:16 UTC 2012
#18636: is_tax() returns false when is_category() or is_tag() returns true
--------------------------+----------------------
Reporter: Viper007Bond | Owner:
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Taxonomy | Version: 3.3
Severity: normal | Resolution: wontfix
Keywords: has-patch |
--------------------------+----------------------
Changes (by ericmann):
* cc: eric@… (added)
Comment:
This is definitely an issue. Let's say, for example, you're trying to
filter archive pages for ''all'' taxonomies (categories and tags
included). Right now, you need to do some pretty hackish stuff to make
sure your filter matches what it's supposed to:
{{{
class Demo {
var $taxonomy = '';
function __construct( $tax ) {
$this->taxonomy = $tax;
apply_filters( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
}
function pre_get_posts( $query ) {
if ( ($this->taxonomy == 'post_tags' && $query->is_tag()) ||
($this->taxonomy == 'category' && $query->is_category()) ||
$query->is_tax( $this->taxonomy ) ) {
// do something conditionally
}
return $query;
}
}
}}}
Whereas if `is_tax()` treated categories and posts the same way, you
wouldn't need the additional checks ... just:
{{{
function pre_get_posts( $query ) {
if ( $query->is_tax( $this->taxonomy ) ) {
// do something conditionally
}
return $query;
}
}}}
Considering categories and tags ''are'' taxonomies, why can't we revise
this?
--
Ticket URL: <http://core.trac.wordpress.org/ticket/18636#comment:8>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list