Support

Account

Home Forums ACF PRO Repeater field inside a shortcode function

Unread

Repeater field inside a shortcode function

  • Hello,

    I am trying to create a shortcode and am having trouble with the repeater field inside of it.

    What I expect to happen:
    A working return with left and right output.

    What happens:
    Left is working fine. On the right I am getting syntax error, unexpected 'if' (T_IF) on the first if statement of the repeater field.

    function news_single_shortcode() {
    
        $left .= '<div class="left">
                    <h2>' . get_field("news-title") . '</h2>'
                    . get_field("news-content") .
                '</div>';
    
        $right .= '<div class="right">'
            if( have_rows('news-files') ):
            while ( have_rows('news-files') ) : the_row();
            $file = get_sub_field('news-uploaded');
            if( $file ):
        '<a class="item" href="#" target="_blank">' . $file['filename'] . '</a>
        </div>';
    
        return $left . $right;
    }
    add_shortcode('news_single', 'news_single_shortcode');
Viewing 1 post (of 1 total)

The topic ‘Repeater field inside a shortcode function’ is closed to new replies.