#17290 closed defect (bug) (duplicate)
register_taxonomy_for_object_type('post_tag', 'page') does not include all registered post-types
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Taxonomy | Version: | 3.1 |
| Severity: | normal | Keywords: | |
| Cc: |
Description
Hi,
I use register_taxonomy_for_object_type('post_tag', 'page'); in my plugin TagPages.
Everything works fine, though on a tag-page (is_tag()==true) only posts are shown in the results. I think this might have historical reasons but with the extended 3.0 taxonomy features we should maybe rethink this behavior and set the post_type for tag-pages to all post-tag registered post_types.
Credits go to mitcho who raised this question in a support topic.
Here's the code I plan to use in the next version of TagPages (currently I manipulate the SQL WHERE directly) to include pages in tag-queries:
add_filter('pre_get_posts', array(&$this, 'add_page_to_tags_query'));
function add_page_to_tags_query($query) {
if (is_tag() && !is_admin()) {
/*
if the post_type does not exist,
we create it
*/
if (!array_key_exists('post_type', $query->query_vars))
$query->query_vars['post_type']=array();
/*
if post_type is set to or includes
any or page
there's nothing more to do
*/
if (!empty($query->query_vars['post_type']) && (in_array('any', (array) $query->query_vars['post_type']) || (in_array('page', (array) $query->query_vars['post_type']))))
return $query;
/*
otherwise include post and page
into post_type
*/
$query->query_vars['post_type']=array_unique(array_merge((array) $query->query_vars['post_type'], array('post', 'page')));
}
return $query;
}
Greetz,
Berny
Change History (2)
Note: See
TracTickets for help on using
tickets.

See: #16233