Hi Steve, the plugin uses WordPress own function get_the_terms() which in turn respects the filter “get_the_terms” https://developer.wordpress.org/reference/hooks/get_the_terms/
You could make your filter conditional with an if ( is_feed() ) which would apply for all feed types including sitemaps.
Would that be useful?
Awesome, thanks for the quick reply and suggestion. I’ll give it a shot and then follow up with our solution if we can get it to work.
Thank you in advance for the follow-up. It will be useful for others, I’m sure π
Thanks @ravanh! I’m testing the following solution and it appears to be working. Not sure what the best way is to target the sitemap-news feed/page but for now I’m using if ( strpos( $_SERVER[‘REQUEST_URI’], ‘sitemap-news.xml’ ) !== false )
public function stripSitemapNewsPriorityTerms( $terms, $id, $taxonomy ) {
if ( strpos( $_SERVER['REQUEST_URI'], 'sitemap-news.xml' ) !== false ) {
$priortiyArr = ['priority', 'main-carousel', 'main-headline', 'carousel', 'headline', 'trending'];
foreach ( $terms as $key => $term ) {
if ( in_array( $term->slug, $priortiyArr ) ) {
unset( $terms[$key] );
}
}
}
return $terms;
}
add_filter( 'get_the_terms', array( $this, 'stripSitemapNewsPriorityTerms' ), 10, 3 );
I was thinking more complex by passing through the request filter first… something like this:
function my_filter_terms( $terms ) {
...
}
function my_filter_request( $request ) {
if ( isset($request['feed']) && strpos($request['feed'],'sitemap-news') === 0 ) {
add_filter( 'get_the_terms', 'my_filter_terms' );
}
}
add_filter('request', 'my_filter_request', 0 );
But your solution is much simpler and should therefor be more efficient. As long as the $_SERVER[‘REQUEST_URI’] global is available which is said to not always be the case (on IIS servers as far as I heard).
But if it works for you, it should remain working as long as you stay on the same server. Thanks for haring! π
Sounds good, we have control over our server environment, so I think we should be good checking against $_SERVER[‘REQUEST_URI’].
Thanks again! π
Thinking about it more, I’ll be adding a conditional to check against in the next release. Something like is_sitemap() or other…
I guess one might be able to use is_feed( $feeds ) or $wp_query->is_feed( $feeds ) where $feeds is the feed type ‘sitemap-news’. However, is_sitemap() would probably be more idiot proof.
-
This reply was modified 8 years, 4 months ago by
sjferwerda.
I’ve not tested this but my impression was that doing an is_feed( 'sitemap-news' ) that would (if sitemap-news has been registered as a feed URL) always return true independent of the current request. Only is_feed() without the $feeds parameter will validate for the current request…
Correct me if I’m wrong though π