1

My latest RSS feed shows 20 posts for example, but I want to include a certain category no matter how old the post is (for example, my 'featured' post category), and also just get 1 latest post from this category.

I've been trying to look for plugins, but I'm not exactly sure what it would be called. Any help would be appreciated.

  • Welcome to WordPress Development. What have you tried so far? Plugin recommendations are off topic. – birgire Jan 31 '15 at 11:47
  • Ah ok sorry. I'm quite new to WP development but I'm using this: <?php $feed = get_the_content_feed('rss2'); ?> which obviously gets all the content from the latest feed (depending how many I set). I want to also add a condition to say get the latest feed as above, but also include 1 latest post from a category ID (to always appear in the feed). Sorry I hope I'm making sense – user1472266 Jan 31 '15 at 11:54
0

You can try the following:

/**
 * A sticky feed post from a given category
 *
 * @see http://wordpress.stackexchange.com/a/176706/26350
 */

add_filter( 'the_posts', function( $posts )
{
    if( is_feed() 
        && $tmp = get_posts( array( 'category_name' => 'feed', 'posts_per_page' => 1 ) ) 
    )
        $posts = array_merge( 
            $tmp, 
            wp_list_filter( $posts, array( 'ID' => $tmp[0]->ID ), 'NOT' ) 
        );

    return $posts;
} );

where we prepend a given category post to the feed. Here you have to adjust the feed category slug to your needs. We also make sure that the sticky post isn't duplicated.

  • Hey that's brilliant - I would never have come up with that! Thanks for taking the time – user1472266 Feb 1 '15 at 10:54

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.