WordPress.org

Make WordPress Core

#24812 closed enhancement (wontfix)

register_post_type should allow you to include posts in the main blog

Reported by: unknowndomain Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

When you create a Custom Post Type, there should be an argument like public etc... that allows your post type to be included in the main blog, just like post does.

This could be something like this:

'include_on_home_query' => true,

Example:

register_post_type( 'activity', array(
	'labels' => array(
		'name'               => __( 'Activities' ),
		'singular_name'      => __( 'Activity' ),
		'all_items'          => __( 'All Activities' ),
		'add_new_item'       => __( 'Add New Activity' ),
		'edit_item'          => __( 'Edit Activity' ),
		'new_item'           => __( 'New Activity' ),
		'view_item'          => __( 'View Activity' ),
		'search_items'       => __( 'Search Activities' ),
		'not_found'          => __( 'No Activities found' ),
		'not_found_in_trash' => __( 'No Activities found in Trash' )
	),
	'public' => true,
	'include_on_home_query' => true,
	'menu_position' => 5,
	'menu_icon' => plugin_dir_url(__FILE__) . 'icon.png',
	'supports' => array(
		'title',
		'editor',
		'thumbnail'
	),
	'register_meta_box_cb' => array( &$this, 'register_metabox' ),
	'taxonomies' => array(
		'year'
	),
	'has_archive' => true
) );

Change History (11)

comment:1 @johnbillion20 months ago

  • Cc johnbillion added

comment:2 follow-up: @alexvorn220 months ago

Don't like the idea.

comment:3 in reply to: ↑ 2 @unknowndomain20 months ago

Replying to alexvorn2:

Don't like the idea.

This comment isn't helpful, please provide details why you think it is a bad idea, i.e. what harm it would cause, or why it isn't useful.

The reason I brought it up, is because some CPTs need to be treated like 1st class citizens, they are essentially posts with extra options.

comment:4 @johnbillion20 months ago

I think this has merit. I've used filters in the past to add CPTs into the main loop (which means they show up in feeds too).

comment:5 follow-up: @alexvorn220 months ago

I did not say it is a bad idea.
It is possible to join two post types and to display them on the main page with wp_query.

comment:6 in reply to: ↑ 5 @unknowndomain20 months ago

Replying to alexvorn2:

I did not say it is a bad idea.
It is possible to join two post types and to display them on the main page with wp_query.

I am not quite clear how that would work, however as John says, it isn't impossible to do other ways, but this pretty small patch to core would make CPTs do something they've not easily done before.

comment:7 follow-up: @wonderboymusic20 months ago

filter pre_get_posts - custom post types aren't really supposed to be "posts," I don't see this getting much support

If you want it to show up in your site’s main RSS feed, then it’s probably not a custom post type.

Last edited 20 months ago by wonderboymusic (previous) (diff)

comment:8 in reply to: ↑ 7 ; follow-up: @unknowndomain20 months ago

Replying to wonderboymusic:

filter pre_get_posts - custom post types aren't really supposed to be "posts," I don't see this getting much support

If you want it to show up in your site’s main RSS feed, then it’s probably not a custom post type.

I don't know if I agree, whilst that post makes a convincing argument, the suggestion that every post you might every wish to post is covered by post formats is ludicrous, and a custom UI is often needed.

comment:9 @markoheijnen20 months ago

Personally I don't see this in core too. I do change the post_type with the filter pre_get_posts but 'include_on_home_query' would not give me any control. Also mixing multiple post types in general is a bad idea.

comment:10 in reply to: ↑ 8 @c3mdigital19 months ago

  • Keywords close added

Replying to unknowndomain:

Replying to wonderboymusic:

filter pre_get_posts - custom post types aren't really supposed to be "posts," I don't see this getting much support

If you want it to show up in your site’s main RSS feed, then it’s probably not a custom post type.

I don't know if I agree, whilst that post makes a convincing argument, the suggestion that every post you might every wish to post is covered by post formats is ludicrous, and a custom UI is often needed.

No one is saying that. For these cases you have the pre_get_posts_filter. This argument has been debated before, See: http://core.trac.wordpress.org/ticket/12702#comment:28

comment:11 @helen19 months ago

  • Keywords close removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Closing per comments above - agree on using pre_get_posts.

Note: See TracTickets for help on using tickets.