Last active
September 15, 2024 07:18
-
-
Save frikishaan/36e8a3534edcbf5f0611de5e20dddfe8 to your computer and use it in GitHub Desktop.
Exclude current post from query loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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