0

How can I completely disable the limit on feed items in my RSS feed that WordPress generates? I know you can modify the limit but I want to programmatically disable the limit completely.

1

Right now, as wp-includes/feed-rss2.php is written, there are no ways of doing such thing by using a feed-page-specific hook or filter, so you have to either:

  1. Edit this file manually (which will be broken after every update)
  2. Make a page template with the same content and changing the query arguments before the loop runs (will generate different URLs, not a good choice but it works as expected)
  3. Alter query arguments if the page is a feed. (By using a general hook, like pre_get_posts)

I will explain the 3rd way:

function feed_unlimited_posts( $query ){
       if(is_feed())
            $query->set( 'posts_per_page', -1 );
       return $vars;
}
add_action( 'pre_get_posts', 'feed_unlimited_posts' ); 

Please Note: I haven't done testing on this piece of code, if you did and it worked, please suggest an edit. Thanks.

-1

This is a sample of generating RSS in a template style.

<?php 
/* 
Template Name: Article Feed
*/
$numposts = 10; // number of posts in feed
$posts = query_posts('showposts='.$numposts.'&cat=3');
$more = 1;

header('Content-Type: '.feed_content_type('rss-http').'; charset='.get_option('blog_charset'), true);
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
?>

<rss version="2.0"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:atom="http://www.w3.org/2005/Atom"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    <?php do_action('rss2_ns'); ?>
>
<channel>
    <title><?php bloginfo_rss('name'); wp_title_rss(); ?> - Article Feed</title>
    <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
    <link><?php bloginfo_rss('url') ?></link>
    <description><?php bloginfo_rss("description") ?></description>
    <lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
    <?php the_generator( 'rss2' ); ?>
    <language><?php echo get_option('rss_language'); ?></language>
    <sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
    <sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
    <?php do_action('rss2_head'); ?>
    <?php while( have_posts()) : the_post(); ?>

    <item>
        <title><?php the_title_rss(); ?></title>
        <link><?php the_permalink_rss(); ?></link>
        <comments><?php comments_link(); ?></comments>
        <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
        <dc:creator><?php the_author(); ?></dc:creator>
<?php the_category_rss(); ?>
        <guid isPermaLink="false"><?php the_guid(); ?></guid>
<?php if (get_option('rss_use_excerpt')) : ?>

        <description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php else : ?>

        <description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
    <?php if ( strlen( $post->post_content ) > 0 ) : ?>

        <content:encoded><![CDATA[<?php the_content() ?>]]></content:encoded>
    <?php else : ?>

        <content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded>
    <?php endif; ?>
<?php endif; ?>

        <wfw:commentRss><?php echo get_post_comments_feed_link(); ?></wfw:commentRss>
        <slash:comments><?php echo get_comments_number(); ?></slash:comments>
<?php rss_enclosure(); ?>
<?php do_action('rss2_item'); ?>

    </item>
    <?php endwhile; ?>

</channel>
</rss>

In this code the no. of post is limited to 10 of one particular category. I hope you need to work around in order to fulfill your need.

If you also generate your own query (possibly using wp_query) and then use the returned array to fill the fields for the RSS

For reference: Digging WP's article on customizing RSS feeds

P.S: code not tested.

  • It is not necessary to create a new feed include markup. A change of the query for the feed is enough and makes not necessary to maintain the feed markup. – bueltge Sep 25 '17 at 7:21

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.