[wp-trac] [WordPress Trac] #17290: register_taxonomy_for_object_type('post_tag', 'page') does not include all registered post-types

WordPress Trac wp-trac at lists.automattic.com
Sat Apr 30 10:58:24 UTC 2011


#17290: register_taxonomy_for_object_type('post_tag', 'page') does not include all
registered post-types
--------------------------+-----------------------------
 Reporter:  neoxx         |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Taxonomy      |    Version:  3.1
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 Hi,

 I use `register_taxonomy_for_object_type('post_tag', 'page');` in my
 plugin [http://wordpress.org/extend/plugins/tagpages/ 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
 [http://wordpress.org/support/topic/plugin-tagpages-why-not-use-builtin-
 taxonmy-functionality#post-2030729 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

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/17290>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list