Support

Account

Home Forums Add-ons Repeater Field how would you create multiple galleries with ACF? Reply To: how would you create multiple galleries with ACF?

  • function mbgc_gallery_shortcode( $atts ) {
    
        // $post_id = $atts['id'];
    
        extract( shortcode_atts(
            array(
                'id' => '',
            ), $atts )
        );
    
        $html_out = '123';
    
        // $post = get_post( $id );
    
        // if ( $post ) :
    
            if( have_rows('mbgc_gallery') ):
    
                $html_out .= '<div class="mbgc-gallery owl-carousel owl-theme">';
    
                while( have_rows('mbgc_gallery') ): the_row(); 
    
                    // vars
                    $image = get_sub_field('mbgc_image');
                    $caption = get_sub_field('mbgc_caption');
                    $title = get_sub_field('mbgc_title');
                    $sub_title = get_sub_field('mbgc_sub_title');
    
                    var_dump($caption);
    
                    if ( $image ) :         
                        $html_out .= '<div class="mbgc-gallery-item">';
    
                            if ( $caption ) : 
                                $html_out .= '<div class="mbgc-slide-caption">';
                                    $html_out .= '<h4>' . $caption . '</h4>';
                                    $html_out .= '<div class="mbgc-slide-titles">';
                                        $html_out .= '<h6>' . $title . '</h6>';
                                        $html_out .= '<h6>' . $sub_title . '</h6>';
                                    $html_out .= '</div>';
                                $html_out .= '</div>';
                            endif;
    
                            $html_out .= '<div class="mbgc-slide">';
                                $html_out .= '<img src="' . $image['url'] . '" alt="' . $image['alt'] . '" />';
                            $html_out .= '</div>';
    
                        $html_out .= '</div>';
                    endif;
    
                endwhile;
    
                $html_out .= '</div>';
    
            endif;
    
        // endif;
    
        return $html_out;
    
    }
    add_shortcode('mbgc_gallery', 'mbgc_gallery_shortcode');

    This is probably out of the scope of what you can help with, but I am trying to write a function based on what you said. Creating a Custom Post Type. I can’t get this to work though. I tried [mbgc_gallery id=”401″] and it outputs nothing, only the test 123. I tried a var_dump and nothing neither. Am I using the repeater code correctly?