WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#12943 closed feature request (worksforme)

Feeds for custom post types

Reported by: matthewhollett Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Feeds Keywords:
Focuses: Cc:

Description

Right now, there is no easy way to get a feed that includes custom post types. The RSS Includes Pages plugin by Marios Alexandrou modifies feeds to include pages, and could easily be updated to apply to other post types. Perhaps this functionality could be included in core.

Change History (7)

comment:1 @rovo895 years ago

  • Cc wordpress@… added
  • Keywords feeds rss custom post types removed

If you want to have a feed for only one custom post type, that's easy: Simply use http://example.com/feed/?post_type=yourposttype.

Queries for multiple post types at once are supported internally, however all request parameters are converted to strings by this line: https://core.trac.wordpress.org/browser/trunk/wp-includes/classes.php?rev=14031#L277. Otherwise you could probably use something like http://example.com/feed/?post_type[]=yourposttype1&post_type[]=yourposttype2.

comment:2 @matthewhollett5 years ago

Thanks, I hadn't realized you could get a feed for a single post type like that. A way to query multiple post types just as easily would be super useful.

comment:3 @rovo895 years ago

Using this in a plugin, the default feed will return the posts of all types:

function myfeed_request($qv) {
	if (isset($qv['feed']))
		$qv['post_type'] = get_post_types();
	return $qv;
}
add_filter('request', 'myfeed_request');

If you use it like that, the post_type parameter in the URL will be ignored, so you might want to add && !isset($qv['post_type']). Also, get_post_types() can be called with attributes that the post type needs have, such as publicly_queryable => true. Or you could use a hardcoded list. Or only apply the filter if some special GET parameter was passed. Or... ;)

comment:4 @scribu5 years ago

  • Milestone 3.0 deleted
  • Resolution set to worksforme
  • Status changed from new to closed

As rovo89 proved, this can be done easily enough already.

comment:5 @matthewhollett5 years ago

Thanks, that works perfectly, and will be very useful for a couple of projects I'm working on.

comment:6 @nacin5 years ago

Careful with that code snippet above -- get_post_types() should be get_post_types( array( 'public' => true ) ), if not a very specific whitelist (for example menu items are public = true).

comment:7 @nacin5 years ago

menu items are no longer public => true.

Note: See TracTickets for help on using tickets.