Make WordPress Core

Opened 17 years ago

Closed 16 years ago

#12730 closed defect (bug) (worksforme)

Custom post types not appearing on core taxonomy pages

Reported by: aizatto Owned by: filosofo
Priority: normal Milestone:
Component: Taxonomy Version: 3.0
Severity: normal Keywords: custom post type, taxonomy
Cc: Focuses:

Description

I'm running into a few problems with using custom post types using a core taxonomy (post_tag). Where visiting the tag page will not display the custom post type.

I have created a custom post type with:

register_post_type('ticket',
	array(
		'label'   => __('Ticket'),
		'public'  => true,
		'show_ui' => true,
		'supports' => array('thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'title', 'editor')
	)	
);

then I registered the post_tag taxonomy to it

register_taxonomy_for_object_type('post_tag', 'ticket');

I created a Ticket, and tagged it (lets say with the tag "lion"). I tried visiting the page for the tag ie ​http://example.com/?tag=lion but it does not show up.

Change History (3)

#1 @matthewhollett
17 years ago

I was running into the same problem, and realized it was basically the same problem I noted in #12943. The workaround that rovo89 posted there works here, too. Here is the code I am using in functions.php to fix both tag pages and feeds - replace "customposttypeone" and "customposttypetwo" with the names of your custom post types.

// Include custom post types in feed and tag requests.
function customrequest($qv) {
	if (isset($qv['feed'])) {
		$qv['post_type'] = array('post', 'customposttypeone', 'customposttypetwo');
 }
 if (isset($qv['tag'])) {
		$qv['post_type'] = array('post', 'customposttypeone', 'customposttypetwo');
 }
	return $qv;
}
add_filter('request', 'customrequest');

I suspect that this is a problem that many people will run into once they start using custom post types, and the solution is not obvious, so it would be great if custom post types could be more closely integrated into core.

Hope this is helpful!

#2 @kevinB
16 years ago

  • Cc kevinB added

#3 @nacin
16 years ago

  • Milestone Awaiting Review
  • Resolution → worksforme
  • Status new → closed

Custom post types now appear on core taxonomy pages. I can't find the ticket, but this is now in core for 3.1.

Note: See TracTickets for help on using tickets.