How to change the quantity of feeds in custom post type?

I created a custom post type “podcast” and all podcasts are inside it. when I visit http://example.com/?feed=podcast, it only shows latest 10 podcasts. How do I change it to 99?

I googled and found the code below:

Read More
function feedFilter($query) {
if (is_feed()) {
    $query->set('posts_per_page','30');
}
return $query;}
add_filter('pre_get_posts', 'feedFilter');

It doesn’t work.

How to customize the feed items quantity in a custom post type?

Related posts

3 comments

  1. The file where the pre_get_posts action runs is wp-includes/query.php, If we look in that file, we’ll see that after the action is executed, the posts_per_page setting is overridden for feeds with this bit of code:

    if ( $this->is_feed ) {
        $q['posts_per_page'] = get_option('posts_per_rss');
        $q['nopaging'] = false;
    }
    

    In this case, we can add a filter to the value of posts_per_rss to customize the feed quantity that way.

    function feed_action( $query ){
        if( $query->is_feed( 'podcast' ) ) {
            add_filter( 'option_posts_per_rss', 'feed_posts' );
        }
    }
    add_action( 'pre_get_posts', 'feed_action' );
    
    function feed_posts(){
        return 99;
    }
    
  2. You can use post_limits filter for feeds, or From backend you should be able to manage post count for feed:

    enter image description here

    Just change it to number of posts in Syndication feeds you want to get.

  3. your code is almost correct.
    I’ve modified somewhat.

    
    
    function feedFilter($query) {
       if (is_feed()) {
         $query->set('posts_per_page','30');
       }
    }
    add_action('pre_get_posts', 'feedFilter');
    

    Above should work

Comments are closed.