Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Query Loops current post id

  • Hey there,
    I’m using GB Query Loop. I want to create a links to a specific posts within the query loop, and for that, I need to add id=”current-post-id” to each gb-grid-column in the loop.

    It should look something like this: <div class=”gb-grid-column gb-grid-column-e05b6adc gb-query-loop-item post-6620″ id=”post-6620″>

    Could you provide the code for a filter or hook?


  • Hi there,

    try this PHP Snippet to add the Post ID to the Query Loop Item:

    // Add post-id-{get_the_id} as ID Attribute on all query loop item
    add_filter( 'generateblocks_attr_grid-item', function( $attributes, $settings ){
    	if ( $settings['isQueryLoopItem'] && !is_admin()  ) {
        	$attributes['ID'] = 'post-'.get_the_id();
    	return $attributes;
    }, 10, 2 );
  • You’re the best, thanks!

  • You’re welcome

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.