Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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.

share|improve this answer
    
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. –  toscho Mar 26 '11 at 5:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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