How To Exclude Post Categories From Related Posts

Molongui » Help » Molongui Authorship Docs » Howto » How To Exclude Post Categories From Related Posts

The Molongui Authorship Pro plugin provides a useful hook so you can filter the categories of posts to display in the related posts section of the author box.

You just need to add the code below to your installation (either via your child theme’s functions.php file or a plugin like Code Snippets). But make sure to edit the list of category IDs to include/exclude to match your needs.

				
					/*
 * Molongui Authorship Pro
 * Filters post categories for related posts displayed in the author box.
 */
add_filter( 'authorship/author/get_posts/args', function( $args, $original_args )
{
  if ( isset( $args['post_type'] ) and $args['post_type'] == 'related' )
  {
     $args['cat'] = "1,-2,3"; // comma-separated list of Category IDs to include/exclude
  }
  return $args;
}, 10, 2 );
				
			
Tip

Note that you can include which categories to list by adding the category ID. And exclude them by adding a minus sign before the ID.

Updated on January 21, 2022

Did not find a solution? We are here to help you succeed.
Open a support ticket