Snippets: Tweak Any Total Grid Query Arguments

/**
 * Example for using the vcex_grid_query filter to tweak a Total VC module Query
 *
 * Important: While it is called vcex_grid_query it will also affect other modules such as the carousels & sliders
 *
 * Learn more about WP_Query arguments : https://codex.wordpress.org/Class_Reference/WP_Query
 *
 * TIP: You can give any module a unique ID so you can check it using $atts['id'] and target modules
 * exclusively
 */
function myprefix_vcex_grid_query( $args, $atts ) {

	//print_r( $atts ); // Un-comment to view current VC module settings

	// Example to exclude the current post on single posts
	// Such as if you are using this module as a related posts section
	if ( is_singular() ) {
		$args['post__not_in'] = array( get_the_ID() );
	}

	// Example to show items from the same category for a module added to portfolio posts
	if ( is_singular( 'portfolio' ) ) {
		$terms = wp_get_post_terms( get_the_ID(), 'portfolio_category' ); // get post terms
		if ( isset( $terms[0] ) ) {
			$args['tax_query'] = array( array(
				'taxonomy' => 'portfolio_category',
				'field'    => 'slug',
				'terms'    => array( $terms[0]->slug ),
			) );
		}
	}

	// Important return the args!
	return $args;

}
add_filter( 'vcex_grid_query', 'myprefix_vcex_grid_query', 10, 2 );
All PHP snippets should be added via a child theme's functions.php file.