• Resolved Jld142

    (@jld142)


    I have 3 post categories: A, B and C.

    If im looking at a post within category A i only want to see related posts that are within category A.

    Likewise if im looking at a Category B post i only want to see related posts that are within category B.

    Can this be done and if so how ?

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

Viewing 1 replies (of 1 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    It is possible, and you’ll need to add the following code to a functionality plugin:

    function jetpackme_filter_exclude_category( $filters ) {
    	if ( in_category( 'category-a' ) ) {
    		$filters[] = array( 'not' =>
    			array( 'terms' => array( 'category.slug' => array( 'category-b', 'category-c' ) ) )
    		);
    	} else if ( in_category( 'category-b' ) ) {
    		$filters[] = array( 'not' =>
    			array( 'terms' => array( 'category.slug' => array( 'category-a', 'category-c' ) ) )
    		);
    	} else if ( in_category( 'category-c' ) ) {
    		$filters[] = array( 'not' =>
    			array( 'terms' => array( 'category.slug' => array( 'category-a', 'category-b' ) ) )
    		);
    	}
    	return $filters;
    }
    add_filter( 'jetpack_relatedposts_filter_filters', 'jetpackme_filter_exclude_category' );

    You can find out more about the different filters you can use to customize Related Posts here:
    http://jetpack.me/support/related-posts/customize-related-posts/

Viewing 1 replies (of 1 total)
  • The topic ‘Only display related posts within the post category’ is closed to new replies.