2

By default WP seems to display all posts of all types in the main RSS feed. You have to add a post_type query variable to show post of a certain type...

So how can I turn this:

http://site.com/feed/?post_type=book

into

http://site.com/feed/books/

?

And if possible rewrite http://site.com/feed/ to http://site.com/feed/blog/, which should display only normal posts...

4

If you set 'has_archive' => TRUE in register_post_type() the post type will have its own feed on /books/feed/ and its items are not included in the main feed.

Example plugin

<?php
/*
Plugin Name: WPSE13006 feed for CPT demo
*/
! defined( 'ABSPATH' ) and exit;

add_action( 'init', 'wpse13006_register' );

// Call wp-admin/options-permalink.php once after activation to make permalinks work
function wpse13006_register()
{
    register_post_type(
        'wpse13006'
    ,   array (
            'has_archive'         => TRUE
        ,   'label'               => 'wpse13006'
        ,   'public'              => TRUE
        ,   'publicly_queryable'  => TRUE
        ,   'query_var'           => 'wpse13006'
        ,   'rewrite'             => array ( 'slug' => 'wpse13006' )
        ,   'show_ui'             => TRUE
        ,   'show_in_menu'        => TRUE
        ,   'supports'            => array ( 'title', 'editor' )
        )
    );
}

Create one post, publish and view it. If you go up one level to /wpse13006/ now, you’ll find the feed at /wpse13006/feed/. The post will not show up in the main feed.

  • thanks, I didn't know about these URLs even though I had has_archive on (but custom post types are still included in the main feed). Do you know if there's a function that returns the rss URL for each post type, or you need to build it manually? – onetrickpony Mar 25 '11 at 11:47
  • @One Trick Pony Strange, the CPTs are never in my main feed. get_post_type_archive_feed_link() should return the feed URI, but it returned always FALSE in my tests. – fuxia Mar 26 '11 at 5:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.