#12943 closed feature request (worksforme)
Feeds for custom post types
| Reported by: |
|
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 (7)
comment:2
matthewhollett — 3 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.
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... ;)
- 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
matthewhollett — 3 years ago
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).

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.