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 WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

requesting Post ID be a dynamic tag able to be inserted

  • There’s Post Title and URLs and such, but there’s no Post ID option. https://share.zight.com/DOuyBWJw

  • Hi there,

    If you want to fetch the Post ID, you can add this snippet:

    add_action('init', function () {
    	if (class_exists('GenerateBlocks_Register_Dynamic_Tag')) {
    		new GenerateBlocks_Register_Dynamic_Tag(
    			[
    				'title'    => esc_html__('Post ID', 'generateblocks'),
    				'tag'      => 'post_id',
    				'type'     => 'post',
    				'supports' => ['source'],
    				'return'   => function ($options, $block, $instance) {
    					$post_id = GenerateBlocks_Dynamic_Tags::get_id($options, 'post', $instance);
    
    					if (! $post_id) {
    						// Fallback if no specific ID is found in the context (should usually be handled by get_id)
    						$post_id = get_the_ID();
    					}
    
    					return GenerateBlocks_Dynamic_Tag_Callbacks::output((string) $post_id, $options, $instance);
    				},
    			]
    		);
    	}
    });

    The Post ID will then be available from the Dynamic Tag selection: https://cln.sh/Z3Dyd1Zn

  • tyvm. is that able to be added to the plugin itself/native?

  • It’s not in the plan at the moment, but it will be considered.

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