• Hey team,

    Any chance you already have or can modify your awesome generateblocks_do_content filter to take in a post ID arg/param?

    We have a mutual customer (GenerateBlocks and Popup Maker customer) who needs to call your filter for multiple popups.

    Here’s a quick proof of concept (POC) that calls your filter in a loop. Let me know if I’m missing something.

    function my_generateblocks_do_content_loop ( $content,  $post_id ) {
        if ( has_blocks( $post_id ) ) {
            $block_element = get_post( $post_id );
    
    		// Where 'popup' is the custom post type for Popup Maker popups.
    		// The original text from the GenerateBlocks doc is 'your_post_type'
    		// https://docs.generateblocks.com/article/adding-content-sources-for-dynamic-css-generation/
            if ( ! $block_element || 'popup' !== $block_element->post_type ) {
                return $content;
            }
    
            if ( 'publish' !== $block_element->post_status || ! empty( $block_element->post_password ) ) {
                return $content;
            }
    
            $content .= $block_element->post_content;
        }
    
        return $content;
    }
    add_filter( 'generateblocks_do_content', 'my_generateblocks_do_content_loop', 10, 2 );
    
    // Popup IDs
    $numbers = array(113, 116);
    
    foreach ($numbers as $post_id) {
        // Get the content using the post ID
        $content = get_post_field('post_content', $post_id);
    
        // Apply the filter and pass the post ID
        $modified_content = apply_filters('my_generateblocks_do_content_loop', $content, $post_id );
    
    } // foreach

    Thanks!

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support David

    (@diggeddy)

    Hi there,

    thanks for the suggestion ill pass this onto the development team for consideration!

    Thanks Mark, David.

    Why not just apply the GB styles whenever the popup is using the ‘block editor’ popup theme?

    Plugin Support David

    (@diggeddy)

    We have a logged an issue for this, we’ll get it included asap.

    For multiple posts you could try this:

    add_filter( 'generateblocks_do_content', function( $content ) {
        $post_ids = array( 467, 468, 469 ); // Change to your Popup Maker popup IDs
    
        foreach ( $post_ids as $post_id ) {
            if ( has_blocks( $post_id ) ) {
                $block_element = get_post( $post_id );
    
                // Where 'popup' is the custom post type for Popup Maker popups.
                if ( ! $block_element || 'popup' !== $block_element->post_type ) {
                    continue;
                }
    
                if ( 'publish' !== $block_element->post_status || ! empty( $block_element->post_password ) ) {
                    continue;
                }
    
                $content .= $block_element->post_content;
            }
        }
    
        return $content;
    } );
    

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Calling generateblocks_do_content with a post ID argument’ is closed to new replies.