Hello,
Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.
When you change the robots meta settings via the filter you shared the sitemap will not see that tag until the page loads and as such it sees the previous robots meta setting and includes it in the sitemap.
To remove the page from the sitemap you need to include its ID in the option to exclude IDs from WordPress Dashboard > Rank Math > Sitemap Settings > General.
Alternatively, you can edit the following filter to parse the URL before getting added to the sitemap and exclude it: https://rankmath.com/kb/filters-hooks-api-developer/#filter-sitemap-item
Don’t hesitate to get in touch if you have any other questions.
Thanks for your quick response. I have over 300 job posts that are currently in my sitemap that shouldn’t be there because of this issue. Excluding them all one by one will thus not be an effective solution.
In the alternative solution I only fix it for the future posts right?
Is there no solution that tells Rank Math to look at all posts on my site again and then decide whether it should add it or not to the sitemap?
Hello,
You can use the alternate method to filter all the URLs, future or existing. Depending on how the data is stored by your theme, the following filter can be further modified and used:
add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ){
if(get_post_type() == 'job_listing' && 1 !== get_post_meta( get_the_ID(), '_filled', true )) {
return $url;
}
}, 10, 3 );
After applying the filter, you might need to follow this screencast to update the sitemap: https://i.rankmath.com/pipRDp
Let us know how that goes.
Thank you.
Thank you Prabhat!
Although your code got rid of all jobs in my sitemap. I’m still new to PHP, so this filter will check whether a post being a job_listing and returns empty for posts which are filled? I don’t really get the empty but I also tried it without it. It all seems to exclude all job posts from my sitemap.
I basically want to exclude all job posts which have meta data where _filled = true OR another option would be to just add a filter for anything that is noindex to be excluded from the sitemap?
Could you please help me with that? Thanks a lot!
Hello,
Please try the below filter:
add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ){
if(get_post_type() == 'job_listing' && true !== get_post_meta( get_the_ID(), '_filled', true )) {
return $url;
}
}, 10, 3 );
Since I don’t have a similar setup like yours, I’m unable to test it. However, let me explain the process to you.
Basically, an approach you can follow is to “return” only those URLs from the filter which are either missing the _filled
status or are not yet filled. Depending upon how the _filled
data is stored, you can modify the condition.
Alternatively, you can share the filter with your theme developers and they should be able to modify it based on the data they store to give you the desired output.
Let us know how that goes.
Thank you.
The annoying thing here is our theme developer is hard to reach and does not properly help us…
So this code works, all job posts now have noindex if their status _filled is 1.
add_filter( 'rank_math/frontend/robots', function( $robots ) {
if(get_post_type() == 'job_listing' && get_post_meta( get_the_ID(), '_filled', true ) && get_the_ID() == '12852') {
$robots["index"] = 'noindex';
$robots["follow"] = 'follow';
}
return $robots;
});
So could you maybe help out in writing a filter that excludes all job posts which have ‘noindex’ ? I think for that you don’t need my setup right?
Would be really helpful and I really appreciate the time you guys are putting in to help me figure this out. Great support!
Hello,
Could you confirm if you tried the filter I shared in my last reply? https://support.rankmath.com/ticket/continuation-of-exclude-custom-post-type-with-specific-status-from-sitemap-4093/?view=all#post-429823
If not, please try it and see if it helps.
If the issue persists, 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.
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.
Hello,
I have updated the sensitive data as requested. Can you please check further?
Thank you.
Hello,
I have updated the sensitive data as requested. Can you please check further?
Thank you.
I indeed tried your solution, but this empties all job listings from our sitemap. I only need the filled jobs to be removed from it.
Thank you very much for the support!
Hello,
The wp-admin you shared seems to be throwing a 404 on our end. Can you please verify so we can further troubleshoot the issue?
Looking forward to helping you on this one.
Thank you.
Hello,
I have updated the sensitive data as requested. Can you please check further?
Thank you.
Apologies, I forgot we changed that permalink for security reasons.
Hello,
I logged into your website’s admin area and modified the filter to get the desired output:
add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ){
$filled = get_post_meta($object->ID, '_filled', true);
if( $filled == 1 ) {
return false;
}
return $url;
}, 10, 3 );
I’ve added the filter in the Code Snippets plugin that was already installed on the website. The Snippet title is Filter Job Sitemap
.
Could you please check and confirm if it is working properly?
Looking forward to hearing back from you.
Thank you.