Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    The category term should be picked up by the permalink for feeds just like it does for regular, non-feed category requests. The feed template is a special kind of loop, the query is supposed to be the same as regular requests. The feed template does not normally affect the query.

    If you request a standard built-in feed do you get only the category posts or all posts? For example: example.com/category/biology/feed/atom/

    There’s likely some other code altering the query in an inappropriate way. Please deactivate all of your plugins and switch to a default twenty* theme. Your problem should be corrected. Switch back to your theme, then activate your plugins one by one. After each change, test for the problem. Once it recurs, the last activated entity is the culprit.

    Thread Starter su1

    (@su1)

    Yes I get only category posts for a standard built-in feed.

    Unfortunately I can’t easily deactivate my theme and/or plugins as it’s a high-traffic website and I can’t lose the functionalities.

    If it helps, these are the first lines of my custom feed:

    $postCount = 5; // The number of posts to show in the feed
    $posts = query_posts('showposts=' . $postCount);
    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="https://purl.org/rss/1.0/modules/content/"
            xmlns:wfw="https://wellformedweb.org/CommentAPI/"
            xmlns:dc="https://purl.org/dc/elements/1.1/"
            xmlns:atom="https://www.w3.org/2005/Atom"
            xmlns:sy="https://purl.org/rss/1.0/modules/syndication/"
            xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
            <?php do_action('rss2_ns'); ?>>
    <channel>
            <title><?php bloginfo_rss('name'); ?> - 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>
            <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(); ?>
    Moderator bcworkz

    (@bcworkz)

    Ah, that’s it! The $posts = query_posts('showposts=' . $postCount); line. This discards the proper query WP has setup and executed, and runs a new query for all posts, 5 at a time. Get rid of this line.

    If you need to limit the feed posts count to 5, set it in Reading Settings. The feed count does not affect regular post queries.

    Good thing you didn’t do the plugin thing! It never occurred to me someone would use query_posts() on a feed template. Any alterations to feed queries can be done through “pre_get_posts” action and verifying the query’s is_feed property is true. No one should be using query_posts() for anything. Its inefficiency is mind boggling. I believe it only exists for reverse compatibility. Even its own reference page states “Its overly-simplistic approach … can be problematic and should be avoided wherever possible.”

    Thread Starter su1

    (@su1)

    Thanks! That was the problem.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom feed specific to a category’ is closed to new replies.