File: /var/www/linde/wp-content/plugins/lindevr-site-plugin/faqs/yoast.php
<?php
/**
* Excludes specific posts from the Yoast SEO sitemap based on an ACF field value.
*
* This function hooks into the 'wpseo_exclude_from_sitemap_by_post_ids' filter provided by
* the Yoast SEO plugin to modify the list of post IDs excluded from the generated XML sitemap.
* It targets posts where a custom Advanced Custom Fields (ACF) field named 'post_visibility'
* has the value 'lva-platform', ensuring these posts are not included in the sitemap.
*/
function exclude_lva_platform_posts_from_sitemap($excluded_ids) {
// Try to get cached excluded posts
$posts_to_exclude = get_transient('excluded_lva_platform_posts');
// If no cache found, run the query
if ( false === $posts_to_exclude ) {
$args = array(
'post_type' => 'linde_faq',
'posts_per_page' => -1,
'fields' => 'ids',
'meta_query' => array(
array(
'key' => 'post_visibility',
'value' => 'lva-platform',
'compare' => '='
)
)
);
$posts_to_exclude = get_posts($args);
// Store in transient cache for 12 hours
set_transient('excluded_lva_platform_posts', $posts_to_exclude, 12 * HOUR_IN_SECONDS);
}
return array_merge($excluded_ids, $posts_to_exclude);
}
add_filter('wpseo_exclude_from_sitemap_by_post_ids', 'exclude_lva_platform_posts_from_sitemap');
?>