function to restrict related post AND has ALL of the same categories
-
I would like to display as a related post only articles in the same category. Why didn’t the function below work?
// This function will only return posts that are related AND has ALL of the same categories. function jp_only_rp_in_same_category( $categories, $post_id ) { $category_objects = get_the_category( $post_id ); if ( ! empty( $categories ) ) { $categories = array_merge( 'categories', 'category_objects' ); return $categories; } else { return $category_objects; } } add_filter( 'jetpack_relatedposts_filter_has_terms', 'jp_only_rp_in_same_category', 10, 2 );
Kind regards.
The page I need help with: [log in to see the link]
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘function to restrict related post AND has ALL of the same categories’ is closed to new replies.