xmlsf_excluded

Filters the response when checking the post for exclusion flags in XML Sitemap context. Passes the post exclusion flag and $post_id; must return true or false.

apply_filters( 'xmlsf_excluded', bool[] $exclude, int[] $post_id )

Used in xml-sitemap-feed/views/feed-sitemap-posttype.php

Parameters (2)

  • $exclude
    (bool) The excluded flag originally fetched by get_post_meta( $post->ID, '_xmlsf_exclude', true ) which defaults to false.
  • $post_id
    (int) The current post ID.

Return

  • (bool) true|false

The filter should return a boolean value signifying the exclusion of the current post. Returning true will exclude the post from the XML Sitemap.

Usage example

function my_custom_exclusion( $exclude, $post_id ) {
	// Exclude by post ID.
	$excluded = array( 210, 5531, 7806 );
	if ( in_array( $post_id, $excluded ) ) {
		return true;
	}

    // Exclude by category ID.
    $cat_id = 123;
    if ( in_array( $cat_id, (array) wp_get_post_categories( $post_id ) ) ) {
        return true;
    }

	// Return original status.
	return $exclude;
}
add_filter( 'xmlsf_excluded', 'my_custom_exclusion', 10, 2 );

Related

Used byDescription
none