Snippets: Related Blog Posts From Current Post 1st Category Only

// Alter the related blog posts query to grab items from first category
add_filter( 'wpex_blog_post_related_query_args', function ( $args ) {
	
	// Get first category
	$cats = wp_get_post_terms( get_the_ID(), 'category' );

	// Get from 1st category only
	$cats['category__in'] = array( $cats[0]->term_id );

	// Return args
	return $args; 

} );

Snippet Type: PHP

Posted Under: Blog

All PHP snippets should be added via a child theme's functions.php file.