Skip to content

Snippet: Exclude the Current Post from Elements

// Exclude Current Post from Any Total Grid/Carousel Module
add_filter( 'vcex_query_args', function( $args, $atts ) {
	if ( wp_doing_ajax() ) {
		$current_id = url_to_postid( wp_get_referer() );
	} elseif ( function_exists( 'vcex_get_the_ID' ) ) {
		$current_id = vcex_get_the_ID();
	} else {
		$current_id = get_the_ID();
	}
	$args['post__not_in'] = array( $current_id );
	return $args;
}, 10, 2 );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top