• Resolved Vimal Roy

    (@vimalroy08)


    Hello,

    We made a change to the default feed settings of WordPress. We need a delay in listing the articles in the WordPress feeds. So we checked for a solution and found the below option to delay posts from displaying on feeds and we added a delay of 20 minutes to list the articles in the feed page.

    https://www.wpbeginner.com/wp-tutorials/how-to-delay-posts-from-appearing-in-wordpress-rss-feed/

    After adding this solution the sitemap-news.xml was also delayed by 20 minutes, We only added delay to the feed pages and not for the sitemaps. We also needed the delay only for the feed pages. Is there any way to fix this issue?  

    Please let me know your feedback.

    Thank you

    • This topic was modified 6 months, 2 weeks ago by Vimal Roy.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi, thanks for reporting this!

    The news sitemap is set up as a feed so indeed the is_feed() conditional applies. Try changing this line:

    if ( is_feed() ) {

    to:

    if ( is_feed() && ( ! function_exists( 'is_sitemap' ) || ! is_sitemap() ) ) {

    Please let me know ??

    • This reply was modified 6 months, 2 weeks ago by Rolf Allard van Hagen. Reason: missing ) in the code suggestion
    Thread Starter Vimal Roy

    (@vimalroy08)

    Hello,

    Thank you for the response.

    We checked your solution, but unfortunately, it is not working. The news site map still doesn’t display the latest news.?

    Do we have a function called is_sitemap() in WordPress? Do you think that will work??

    In the meantime I created a function to exclude the sitemap by using its slug, Please check below code.

    function wpb_snippet_publish_later_on_feed( $where ) {
        global $wpdb;
    
        if ( is_feed() && !is_admin() && !is_sitemap_request() ) {
            // Timestamp in WP-format.
            $now = gmdate( 'Y-m-d H:i:s' );
    
            // Number of units to wait.
            $wait = '20'; // integer.
    
            // Choose time unit.
            $unit = 'MINUTE'; // MINUTE, HOUR, DAY, WEEK, MONTH, YEAR.
    
            // Add SQL-syntax to default $where.
            $where .= " AND TIMESTAMPDIFF($unit, $wpdb->posts.post_date_gmt, '$now') > $wait ";
        }
    
        return $where;
    }
    
    add_filter( 'posts_where', 'wpb_snippet_publish_later_on_feed' );
    
    // Function to check if the current request is for a sitemap.
    function is_sitemap_request() {
        $request_uri = $_SERVER['REQUEST_URI'];
    
        // Check for specific sitemap URL
        if ( strpos($request_uri, 'sitemap-news.xml') !== false ) {
            return true;
        }
    
        return false;
    }

    Can you please check and make sure it is working fine with the plugin? I tested it on my development site and it is working like the way I mentioned (delay only for feeds and the delay does not affect the sitemaps).

    Please check and let me know your thoughts.

    Thank you ??

    Do we have a function called is_sitemap() in WordPress? Do you think that will work? 

    No, but the function is in the sitemap plugin. But I now realize is should have suggested the plugin function is_news() instead:

    if ( is_feed() && ( ! function_exists( 'is_news' ) || ! is_news() ) ) {

    But you can continue using your own (working) code just fine too ??

    Thread Starter Vimal Roy

    (@vimalroy08)

    Hello @ravanh ,

    Thank you for the solution.

    This solution worked ??

    Thanks again

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘The feed delay function delayed the news sitemap also.’ is closed to new replies.