• Resolved underclass

    (@underclass)


    I’m trying to use the customisation of related posts to exclude a category using the code supplied on the help file;

    //Jetpack Related Posts
    function jetpackme_filter_exclude_category( $filters ) {
        $filters[] = array( 'not' => array( 'term' => array( 'category.slug' => 'blog' ) )
        );
        return $filters;
    }
    add_filter( 'jetpack_relatedposts_filter_filters', 'jetpackme_filter_exclude_category' );

    But the category ‘blog’ continues to remain in the results, I have tried other hooks successfully (headline change, remove context) but removing any of the category slugs does not work. Defaulting to 2014/15 themes does not seem to have any effect.

    https://wordpress.org/plugins/jetpack/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Ryan C.

    (@ryancowles)

    The code snippet that you provided looks like it should be working. Could you let me know where exactly you are adding it on your site?

    Thread Starter underclass

    (@underclass)

    This is being added to the functions file in a child theme, I am successfully using code to exclude related posts from being rendered in the blog category as outlined in another thread;

    https://wordpress.org/support/topic/how-to-exclude-related-posts-from-all-the-posts-of-a-category?replies=6

    function jetpackme_remove_rp() {
        $jprp = Jetpack_RelatedPosts::init();
        $callback = array( $jprp, 'filter_add_target_to_dom' );
        if ( in_category( 'blog' ) ) {
            remove_filter( 'the_content', $callback, 40 );
        }
    }
    add_filter( 'wp', 'jetpackme_remove_rp', 20 );

    To test, should I need to re-index posts using debug on 2014/2015 themes?

    Thread Starter underclass

    (@underclass)

    I have noticed that changing the slug does have an effect on the output of the related posts.

    I am using print, digital, photography and blog categories – using different slugs does exclude the category from the related posts.

    I am able to exclude print, photography and digital, but not blog.

    Plugin Contributor Ryan C.

    (@ryancowles)

    Thanks for the additional information! Is blog the default category for new posts?

    Thread Starter underclass

    (@underclass)

    It is

    Plugin Contributor Ryan C.

    (@ryancowles)

    Gotcha. I suspect that might be part of the issue. If you take a look at the section about excluding categories here:
    http://jetpack.me/support/customize-related-posts/#exclude-cats

    You’ll notice the second snippet in that section excludes the default uncategorized category from Related Posts. Since blog is your default category, I would suggest trying that approach.

    Let me know how that works for you!

    Thread Starter underclass

    (@underclass)

    That works perfectly, thank you, I should have thought to try that earlier. May I suggest that the help file is edited to include a line about default categories?

    Thanks for your help!

    Plugin Contributor Ryan C.

    (@ryancowles)

    Glad to hear that did the trick! We’ll get the support doc updated to better explain this.

    Please let me know if there is anything else that I can help with!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Exclude an entire category from ever appearing among Related Posts results’ is closed to new replies.