Skip Navigation

[Resolved] Remove some CPTs (based on a custom field) from sitemap

This support ticket is created 2 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 2 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#2527367

Tell us what you are trying to do?
I want to selectively eliminate some custom post types from this sitemap file: hidden link for which a custom field called "Show on website" (slug: show-on-website) is "No".

I already have included this meta tag using dynamic conditions (it only shows when flag above is "no"):

<meta name="robots" content="noindex">

Is there any documentation that you are following?
None

Is there a similar example that we can see?
None that I'm aware of

What is the link to your site?
hidden link

#2527603

Hello,

It depends on the sitemap plugin you are using.

I assume you are using Yoast SEO plugin to generate the XML sitemap, you can follow their document to exclude those posts which custom field "show-on-website" values are "No":
hidden link
section "Exclude specific posts"

You can get all post IDs which custom field "show-on-website" values are "No" using WordPress built-in class WP_Query:
https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters

One thing need to pay attention:
If the custom field "show-on-website" is created with Toolset Types plugin, in your custom PHP codes, you need to add "wpcf-" prefix before field slug, for example: "wpcf-show-on-website"
https://toolset.com/documentation/customizing-sites-using-php/functions/