Support

Account

Home Forums General Issues ACF block repeater shortcode issue.

Unread

ACF block repeater shortcode issue.

  • I’m really struggling here. I created the below shortcode in functions and when i use the shortcode three times on a single page it fails. It only outputs the first one and then fails on the other two.

    Basically I have an ACF block which is a tab repeater. When I insert the shortode into the first three tabs (repeater fields) it executes the first and not the rest.

    Can anyone spot what I might be doing wrong here?

    Thanks

    function insert_another_page_content($atts) {
        ob_start();
    
        extract(shortcode_atts(array( 
            'post_id' => null
        ), $atts));
        
        $post_id = $post_id;
        $post = get_post( $post_id ); 
        
        if ( has_blocks( $post->post_content ) ) {
            $content = 
                    $blocks = parse_blocks( $post->post_content );
                    foreach( $blocks as $block ) {
                        echo render_block( $block );
                    }
        };
        
        return ob_get_clean();
    }
    add_shortcode('insert', 'insert_another_page_content');
    # [insert post_id="0"]
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.