• Hi, thank you for this plugin.

    I’m pulling in content using WP_Query and a “while ( have_posts() ) : the_post()” loop, using the_content() to output the post.

    How can I ensure the generateblocks_do_content filter is being called for each post in the loop so that the CSS for each post can be generated?

    So something like this, which isn’t working because the filter is not called within the loop:

    
    add_filter( 'generateblocks_do_content', function( $content ) {
        
        $post_id = get_the_ID(); // A post ID to check the content of. Can be dynamically set.
    
        if ( $post_id && has_blocks( $post_id ) ) {
            $block_element = get_post( $post_id );
    
            if ( ! $block_element ) {
                return $content;
            }
    
            if ( 'publish' !== $block_element->post_status || ! empty( $block_element->post_password ) ) {
                return $content;
            }
    
            $content .= $block_element->post_content;
        }
    
        return $content;
    } );
    
Viewing 1 replies (of 1 total)
  • Plugin Author Tom

    (@edge22)

    Hi there,

    You’ll need to query the posts inside the function and loop them.

    For example:

    add_filter( 'generateblocks_do_content', function( $content ) {
        $query = new WP_Query();
    
        if ( $query >have_posts() ) {
            while ( $query->have_posts() ) {
                $query->the_post();
                $post_id = get_the_ID();
    
                if ( $post_id && has_blocks( $post_id ) ) {
                    $content .= get_the_content();
                }
            }
        }
    
        return $content;
    } );

    Hope this helps!

Viewing 1 replies (of 1 total)
  • The topic ‘generateblocks_do_content in loop’ is closed to new replies.