Hi,
I am creating a photography portfolio website. I have created a custom post type called Galleries and inside that, there are posts named Portrait, Wildlife, Landscape.
Inside every post, there is an ACF field called gallery with photos of the above categories.
I want to create a home page called overview and show all the photos from galleries inside the custom posts.
Does anyone have any idea on how to achieve this?
Just like showing any posts.
You do a WP_Query to get the list of posts. You loop over those posts. You get the fields for each post and display them.
You can achieve this using WP_Query to fetch all “Galleries” posts and retrieve images from the ACF gallery field. Try this:
php
Copy
Edit
<?php
$query = new WP_Query([‘post_type’ => ‘galleries’, ‘posts_per_page’ => -1]);
if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
$images = get_field(‘gallery’);
if ($images) : foreach ($images as $image) :
echo ‘
‘;
endforeach; endif;
endwhile; wp_reset_postdata(); endif;
?>
I used a similar approach on Photoapkleap site to handle image content. Hope this helps!