Ticket #12943 (closed feature request: worksforme)

Opened 22 months ago

Last modified 16 months ago

Feeds for custom post types

Reported by: matthewhollett Owned by:
Priority: normal Milestone:
Component: Feeds Version: 3.0
Severity: normal Keywords:
Cc: wordpress@…

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

  • 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.

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.

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

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

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

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

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

menu items are no longer public => true.

Note: See TracTickets for help on using tickets.