Skip to content

Instantly share code, notes, and snippets.

@frikishaan
Last active September 15, 2024 07:18
Show Gist options
  • Save frikishaan/36e8a3534edcbf5f0611de5e20dddfe8 to your computer and use it in GitHub Desktop.
Save frikishaan/36e8a3534edcbf5f0611de5e20dddfe8 to your computer and use it in GitHub Desktop.
Exclude current post from query loop
<?php
/*
* In this example, we are excluding the current post from a list in Generate Press query loop
*/
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
// apply filter if loop has class: recent-posts-grid
if (! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'recent-posts-grid' ) !== false) {
$query_args = array_merge( $query_args, array(
'post__not_in' => array( get_the_ID() )
)
);
}
return $query_args;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment