Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#17290 closed defect (bug) (duplicate)

register_taxonomy_for_object_type('post_tag', 'page') does not include all registered post-types

Reported by: neoxx's profile neoxx Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: Taxonomy Keywords:
Focuses: Cc:



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))

		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;


Change History (2)

#1 @dd32
13 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

See: #16233

#2 @neoxx
13 years ago

thanks for the pointer :)

Note: See TracTickets for help on using tickets.