Site logo

Archived topic

How to Make List element for Related Post

3 replies · Started by Maggie on August 2, 2022

Viewing posts 1–4 of 4

Hi Maggie,

You can use GenerateBlocks' query loop block to do so.

If you are using GB pro, there's an option built in to exclude the current post.

If you are not using GB pro, try using this method:

1. Add no-current-post class to the Grid block under the query loop block

2. Add this PHP snippet:

add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
    if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'no-current-post' ) !== false ) {
        
		$query_args['post__not_in'] = [get_the_ID()];
    }

    return $query_args;
}, 10, 2 );

Hi, Do you have discount code fore purchasing GB pro. Thanks

This archived topic is closed to new replies.