skip to Main Content

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; 

} );
All PHP snippets should be added via child theme's functions.php file or via a plugin (we recommend Code Snippets)
Back To Top