Make RSS think posts are new?

Here’s one idea how we could get a full control over our newsletter feed:

Feed with custom posts selection and drag/drop ordering:

We can use the navigational menu UI, to select exactly what posts to display in the feed and sort them with drag/drop.

We need to follow these two steps:

Step 1) Create a menu with the menu name newsletter under the /wp-admin/nav-menus.php page:
:

Select newsletter posts

where we add all the posts, to the menu, that we need to include in the newsletter.

Then we order them as needed with the drag/drop feature of the menu UI.

Step 2) Use the following code snippet:

/**
 * Custom Newsletter Feed
 *
 * Supports drag/drop for feed items.
 *
 * Create a menu with the 'newsletter' menu name and 
 * access the feed at /feed/?wpse_feed=newsletter
 *
 * @see http://wordpress.stackexchange.com/a/186121/26350
 */

add_action( 'pre_get_posts', function( $q )
{
    $menu = 'newsletter'; // Our custom nav menu.

    if(    $q->is_feed()
        && $menu === filter_input( INPUT_GET, 'wpse_feed' )
    ) {
        $q->set( 'post__in', 
            (array) wp_list_pluck( 
                wp_get_nav_menu_items( $menu ), 
                'object_id' 
            ) 
        );
        $q->set( 'orderby',   'post__in' );
        $q->set( 'post_type', 'any'      );

        //-------------------------------------------------
        // Modify the pubDate. 
        // Let the first post be created at midnight 
        // and then add 1 sec for each get_post_time() call
        //--------------------------------------------------
        add_filter( 'get_post_time', function ( $time, $d, $gmt )
        {
            static $count = 0;
            return date( $d, strtotime( 'midnight' ) + $count++ );
        }, 10, 3 );

    }
} );

Here we modify the pubDate to start at midnight, and then we add 1 second for each call to the get_post_time() function. So the posts will all have different pubDate and it will be different from the day before.

Then we can access our custom made newsletter feed at:

http://example.tld/feed/?wpse_feed=newsletter

This could be expanded to support more custom made feeds, but hopefully you can adjust this to your needs.

Leave a Comment