Snippets: Tweak Any Total Grid Query Arguments

Important: You can now enter use the "Advanced Query" setting in any Total module and enter a callback name for the Query arguments. This is more efficient then using the filter mentioned below and also makes it easier for targeting specific grids and re-using custom queries.

Any Total module you use that displays posts (Portfolio Grid, Blog Grid, Post Types Grid...etc) passes it's Query arguments to the "vcex_grid_query" filter which you can use in a child theme to modify the query to set your own custom arguments. See example below:

 * 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 :
 * TIP: You can give any module a unique ID so you can check it using $atts['id'] and target modules
 * exclusively
add_filter( 'vcex_grid_query', function( $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;

}, 10, 2 );
All PHP snippets should be added via a child theme's functions.php file or via the Code Snippets Plugin (or alternative plugin)