Snippets: Allow Portfolio Grid Sort by Date

// This function alters the Visual Composer Grid modules post Query such as the "Portfolio grid"
// module. So you can visit the URL like this: site.com/sort_year=2016 for example to display items only
// from 2016. This will work for any Total VC grid module.
// You can rename "sort_year" to anything you want except "year" because it will conflict with WordPress functions
// so it's best to keep it prefixed.
function myprefix_vcex_grid_query( $args, $atts ) {

	// Get year param
	$year = ! empty( $_GET['sort_year'] ) ? esc_attr( $_GET['sort_year'] ) : '';

	// Alter query based on year parameter
	if ( $year ) {
		$args['date_query'] = array(
			'year' => $year
		);
	}

	// 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.