Order WordPress RSS feed by modified rather than published

Adding the following to the functions.php of your theme should make the posts in your WordPress RSS feed sort by when the post was last modified rather than when it was published. Useful in some cases when you for example want to push out updated posts as well.

function wpse49312_alter_the_query( $request )
    $dummy_query = new WP_Query();

        $request['orderby'] = 'modified';

    return $request;
add_filter('request', 'wpse49312_alter_the_query');
  • Relok

    this is great!

    However, I noticed that the post edited / updated not go up to the first place in your feed!
    I’d love to have your help, to do this trick!
    waiting for your reply

    Best Regards

    • Not sure what you mean here… that is exactly what this does. It sorts the feed by modified (edited/updated) rather than the default, published.

      • Relok

        This is true, but the release date remains the same, then the modified feed remains at the bottom and not at the top (at the top of the page).

        • If you’re talking ordering on the blog and in the RSS feed file itself, then I don’t know, and personally don’t really care either actually. My main goal was that it should be picked up by RSS readers if I did an update of an old post, which they do as far as I have experienced. If you need to display them in that order as well, I don’t know how to do that. If you’re using the RSS feed somewhere else I would probably just reorder the items there actually. Let me know if you work it out and the fix isn’t too complicated though 🙂

          • Relok

            I mean obviously in the rss feed
            maybe you can offer your help for this?
            would be great

          • Sorry, but I have no time nor interest in doing that for you. Can’t imagine it should be too difficult though, so you’ll probably figure it out if you give it a shot. Good luck, and please check back if you find a solution to it so I can potentially update the blog post 🙂

  • Thanks very much for the code… I have added it to the functions.php and now await to see if it picks up my posts. My site is a movie site that posts movie trailers using the IMDB info and as I have chosen the posts to use the movie release date, some of the older movies get buried under other posts and are not picked up by the rss feed. Could you please tell me if there is a way that this code could be applied to the posts previously posted or is it only good for the new files that are added after the code was added…. thanks again…

    • Well, the RSS feed just lists whatever is in the database. So when this is added, you should see a difference in your feed immediately. At least as long as there are differences in recent published and updated timestamps. How RSS readers react to this change I’m not sure though.

  • ty Tor 4 your fast reply… I will let you know how it goes…

  • kwikshowmehow2

    I want to use your code but with a custom post type – mine is
    feed/?post_type=listing – so how would I modify your code to make that
    custom post type work? Thanks!