jetpack
jetpack copied to clipboard
Excluding multiple categories from Related Posts disables it completely
Impacted plugin
Jetpack
Steps to Reproduce
- Make sure that Jetpack is installed and connected to a WordPress.com account.
- Enable the Related Posts Feature
- Filter categories by using the snippet for that:
- Related Posts stop from working.
A clear and concise description of what you expected to happen.
Related Posts working on all posts except the ones on the categories filtered.
What actually happened
Related Posts is disabled on all posts.
Other information
This initially came through the forums: https://wordpress.org/support/topic/jetpackme_filter_exclude_category/?view=all
Operating System
No response
OS Version
No response
Browser
Firefox
Browser Version(s)
No response
This snippet is working for me:
function jetpackme_filter_exclude_category( $filters ) {
$filters[] = array(
'not' => array(
'terms' => array(
'category.slug' => array(
'examplecategory',
'secondcategory',
),
),
),
);
return $filters;
}
add_filter( 'jetpack_relatedposts_filter_filters', 'jetpackme_filter_exclude_category' );
For posts that only had those two categories, sometimes the Related Posts remain, I also noticed sometimes they don't, but I suspect that is due to lack of any relatable content.