How to add dynamic post type in sitemap?

#255488
  • Resolved Serii_burduja
    Rank Math free

    Hi.
    I created page ads.
    And on this page i got content dynamicaly with fetch throw javascript from get parameter.
    The single page for dynamic post look like this https://www.imprendocasa.it/ads/?id=604


    fetch('my-site/api/realestate/v1/immobili/<?php echo $_GET['id']; ?>', {
    method: 'GET',
    headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'authkey': 'xxxx',
    // 'appkey': 'xxx'
    'appkey': 'xxx'
    },
    })
    .then((resp) => resp.json())
    .then((resp) => {
    this.single = resp.data[0];
    this.loading = false;
    })
    .catch(error => {
    console.log(error, 'error from single immobile')
    });

    And i want to add those posts in sitemap.

    I found 2 filters, but i can’t understand how them works.


    add_filter('rank_math/sitemap/index', function ($xml) {
    $xml .= '
    <sitemap>
    <loc>https://www.imprendocasa.it/ads-sitemap.xml</loc>
    <lastmod>2021-09-14T20:34:15+20:00</lastmod>
    </sitemap>';
    return $xml;
    }, 11);


    add_filter('rank_math/sitemap/${type}/content', function () {
    return '
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
    <loc>https://www.imprendocasa.it/ads/?id=701</loc>
    <lastmod>2020-09-14T20:34:15+00:00</lastmod>
    </url>
    </urlset>';
    });

    For sitemap_index i have just page sitemap https://i.imgur.com/IPCAcrW.png

    Thanks in advance.

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

    Thank you for contacting the support, and sorry for any inconvenience that might have been caused due to that.

    Please note that you need to replace {$type} with either post or page or any other custom post type that you want to register and then add the URLs with an option of using some custom logic to an array and return it.

    After doing so, please clear your browser cache or follow this video screencast and the changes should reflect to the sitemap pages: https://i.rankmath.com/pipRDp

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    I think this filter doesn’t work.

    	add_filter('rank_math/sitemap/index', function ($xml) {
    		$xml .= '
    		<sitemap>
    			<loc>https://www.imprendocasa.it/ads-sitemap.xml</loc>
    			<lastmod>2021-09-14T20:34:15+20:00</lastmod>
    		</sitemap>';
    		return $xml;
    	}, 11);

    I think, if i will add them, i will get a new line like for pages.
    https://www.imprendocasa.it/page-sitemap.xml
    https://www.imprendocasa.it/ads-sitemap.xml

    But i got just pages.

    https://i.imgur.com/H6AzguQ.png

    I can’t uderstand what does first filter?

    	add_filter('rank_math/sitemap/index', function ($xml) {
    		$xml .= '
    		<sitemap>
    			<loc>https://immobiliareclass.com/new-sitemap.xml</loc>
    			<lastmod>2020-09-14T20:34:15+00:00</lastmod>
    		</sitemap>';
    		return $xml;
    	}, 11);

    If i will insert this filter, what will happened?
    On the sitemap_index.xml will appear a new Url from filter?
    https://immobiliareclass.com/new-sitemap.xml

    For this moment this url doesn’t appear.

    And how first filter works with second

    	add_filter('rank_math/sitemap/ads/content', function () {
    		return '
    		<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    			<url>
    				<loc>https://www.imprendocasa.it/ads/?id=701</loc>
    				<lastmod>2020-09-14T20:34:15+00:00</lastmod>
    			</url>
    		</urlset>';
    	});

    I replaced ${type} with ads.

    In the second filter we don’t have info about first.

    Hello,

    To achieve this you might need to create a custom sitemap by following this tutorial: https://rankmath.com/kb/custom-sitemaps/

    The filters that you are trying to add are not correct and even if they were called properly they only serve the purpose of modifying already created sitemaps, not creating new ones.

    For this, you should follow the tutorial mentioned above.

    Hope this helps solve your issues.

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

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘How to add dynamic post type in sitemap?’ is closed to new replies.