• Eric

    (@crookeddesigns)


    In the WP Engineer article Publish the Feed Later, they describe how to delay publishing the feeds by a specific amount of time using the following code:

    /**
    * publish the content in the feed later
    * $where ist default-var in WordPress (wp-includes/query.php)
    * This function an a SQL-syntax
    */
    function publish_later_on_feed($where) {
    global $wpdb;
    if ( is_feed() ) {
    // timestamp in WP-format
    $now = gmdate('Y-m-d H:i:s');
    // value for wait; + device
    $wait = '5'; // integer
    // http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
    $device = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
    // add SQL-sytax to default $where
    $where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
    }
    return $where;
    }
    add_filter('posts_where', 'publish_later_on_feed');

    This code works perfectly to delay publishing all articles of all post-types to the RSS feed by 5 minutes.

    What I’d like to do is a bit more complex. I’d like to be able to delay articles from specific custom post types being published on the feed by set amounts of time, something along the lines of:

    if the custom post type is “alpha”, delay posting to feed by 5 minutes.
    if the custom post type is “beta”, delay posting to feed by 1 hour.
    if the custom post type is “gamma”, delay posting to feed by 1 day.

    I’ve tried several methods of getting this to work without success and would greatly appreciate any advice to get me headed in the right direction.

  • The topic ‘Delay publishing articles from custom post types to feed’ is closed to new replies.