WordPress.org

Ready to get started?Download WordPress

Forums

Main RSS Feed - Show only posts from one category (5 posts)

  1. Maraki
    Member
    Posted 3 months ago #

    I would like to have my main RSS feed to show posts from one category only.

    Is there a function that can help me achieve this?

  2. bcworkz
    Member
    Posted 3 months ago #

    Not exactly, you make your own! You use the same technique as would be done to alter any posts query. Hook into the 'pre_get_posts' action. Use is_feed() to verify the query is for a feed, then set either 'cat' or category_name' query vars to restrict the query to the specified category ID or slug.

  3. Maraki
    Member
    Posted 3 months ago #

    I understand what you are saying but I am not that good with the actual coding -:)

  4. bcworkz
    Member
    Posted 3 months ago #

    Enter your actual category slug (not name!) where indicated. Place in functions.php:

    add_action('pre_get_posts', 'mki_feed_cat');
    function mki_feed_cat( $query ) {
       if( is_feed() ) $query->set('category_name', 'YOUR_CAT_SLUG');
    }

    FYI, I'm giving you the code only because it is so brief. For future reference, you're more likely to to get help if you first make an effort yourself to solve your problem. There's several examples in the reference very close to this. You could have figured this out. Maybe you make a mistake and it doesn't work. Now you can show you made a reasonable effort yourself and just need a quick pointer.

    That will get you much farther than asking for free turnkey coding service, and you'll likely learn something along the way :)

  5. Maraki
    Member
    Posted 3 months ago #

    thank you but i am an accountant! I have come this far to understand how to ask coding questions :) but i am getting better slowly slowly!

    I will give this a go ;)

Reply

You must log in to post.

About this Topic