Home Forums ACF PRO Repeater field inside a shortcode function


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") .
        $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>
        return $left . $right;
    add_shortcode('news_single', 'news_single_shortcode');
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.