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

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;
}

Leave a Comment