Custom Sitemap not Updating

#561230
  • Resolved Anonymous
    Rank Math free

    Added a custom sitemap to the site. However it’s not updating.

    Using add_filter( 'rank_math/sitemap/enable_caching', '__return_false'); Disables the Custom Sitemap.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.

    Could you please share the custom sitemap URL you have created so we can check?

    Also, please share the code you have used to create the custom sitemap. You can paste it using this tool and add the generated link here.

    Looking forward to helping you.

    Thank you.

    Anonymous
    Rank Math free

    Location: https://staging.localbridalexpos.com/sitemap_index.xml

    if( class_exists('RankMath\Post') ){
        include_once 'functions-rankmath_sitemap.php';
        add_filter('rank_math/sitemap/providers', function( $external_providers ) {
            $external_providers['local'] = new \RankMath\Sitemap\Providers\Custom();
            return $external_providers;
        }
    }

    functions-rankmath_sitemap.php

    namespace RankMath\Sitemap\Providers;
    
    defined( 'ABSPATH' ) || exit;
    
    class Custom implements Provider {
    
        public function handles_type( $type ) {
            return 'local' === $type;
        }
    
        public function get_index_links( $max_entries ) {
            return [
                [
                    'loc'     => \RankMath\Sitemap\Router::get_base_url( 'local-sitemap.xml' ),
                    'lastmod' => find_monday() . 'T16:01:26+00:00',
                ]
            ];
        }
    
        public function get_sitemap_links( $type, $max_entries, $current_page ) {
            global $wpdb;
            $results = $wpdb->get_results("SELECT city, region, impressions FROM geo_loc WHERE impressions >= 1 ORDER BY region, city LIMIT 50000");
    
            if( !empty( $results ) ) {
                $links = array();
                $urls = array();
                $i = 0;
    
                foreach( $results as $geo_loc ){
                    $local_url = $page_url . $geo_loc->region . '/' . str_replace(" ", "_",$geo_loc->city) . '/';
                    if( empty($urls) ||  !in_array($local_url, $urls) ){
                        $links[$i]['loc'] = $local_url;
                        $i++;
                    }
                }
            }
    
            return $links;
        }
    
    }

    Hello,

    The custom sitemap should not be disabled upon using this line in your functions.php file as it only clears the sitemap cache.

    However, if it’s getting disabled upon doing so, we might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Thank you.

    Anonymous
    Rank Math free

    Information Added.

    Hello,

    When trying to login to the staging website with the credentials shared in the sensitive data section we get the message that the username RankMath doesn’t exist.

    Could you please verify the same and get back to use so we can debug the issue?

    Looking forward to helping you.

    Anonymous
    Rank Math free

    Should be working now.

    Hello,

    We just checked the situation on the website and the reason you are not seeing the data when you clear the cache is that it tries to load the custom functions you have for the sitemap but the variable $links is not defined because the variable $results is empty for the current query in the staging website.

    We dumped the results of the $results variable and it returned an empty array so the rest of the function fails and the variable $links it’s only defined if you have results.

    Essentially, you don’t have any results for this custom sitemap, using your custom query, so it would return a 404 error.

    Don’t hesitate to get in touch if you have any other questions.

Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this ticket.