jetpack icon indicating copy to clipboard operation
jetpack copied to clipboard

Excluding multiple categories from Related Posts disables it completely

Open muffinpeace opened this issue 4 years ago • 1 comments

Impacted plugin

Jetpack

Steps to Reproduce

  1. Make sure that Jetpack is installed and connected to a WordPress.com account.
  2. Enable the Related Posts Feature
  3. Filter categories by using the snippet for that:
  4. 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

muffinpeace avatar Apr 29 '22 21:04 muffinpeace

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.

coder-karen avatar May 02 '22 16:05 coder-karen