Using free ACF Galerie 4 with Bricks

I was asked to figure out how to use a free version of ACF Galerie 4 in Bricks.

If you create a field you can use it in elements like Carousel in the query loops. As this field won’t show up in the dynamic data dropdown you need a custom function that will fetch it or you. You can add it in functions.php or using plugins like WPCodebox.

function get_portfolio_gallery($field_name){
    
    //Get the ID of the portfolio item currently in loop
    $portfolio_id = get_the_ID(); 
    
    //Get the field data
    $portfolio_gallery = get_field($field_name, $portfolio_id);
    
    //Get only IDs of these images as this is what Carousel and Gallery elements expect to get
    $gallery_img_ids = array();
    foreach ($portfolio_gallery as $image_data) {
		$gallery_img_ids[] = $image_data["attachment"] -> ID;
    }
    
    return $gallery_img_ids;
}

Which you then use in something like a Carousel by choosing Type “Media” and this function as dynamic data {echo:get_portfolio_gallery(gallery_field_name)}. Of course change the “gallery_field_name” to a field name that you’ve set up.

1 Like