For a holiday home website (for context) – I’ve created a few Gutenberg blocks using ACF – such as a gallery slider.
I now have a Gutenberg block called ‘Property Previews’ which is a Relationship field. The idea being the user can insert a block called Property Previews, select which properties they want to display on that page, and it’ll show content from that Property page.
The issue I’m having is returning the ACF fields from the Gallery slider, within the Relationship field. I got as far as this, but this just retuns every single content block from the Property page, instead of just the hero slider. I also only want to return the image field from the Gallery Slider, instead of the whole block as I need to customise the slider. Any help?
<?php
$previews = get_field('select_property');
if( $previews ): ?>
<div class="property-previews">
<?php foreach( $previews as $preview ):
$permalink = get_permalink( $preview->ID );
$title = get_the_title( $preview->ID );
?>
<article class="property-previews__card">
<a>"><h2><?php echo esc_html( $title ); ?></h2></a>
<?php
if ( has_blocks( $preview->post_content ) ) {
$blocks = parse_blocks( $preview->post_content );
foreach ($blocks as $block) {
if ($block['blockName'] === 'acf/hero-gallery-slider');
echo render_block($block);
}
} ;
?>
</article>
<?php endforeach; ?>
</div>
<?php endif; ?>
This is what my Gallery Slider code looks like:
<?php
$images = get_field('hero_gallery_slider');
if( $images ): ?>
<div class="hero-gallery-slider-main">
<div class="slider-for">
<?php foreach( $images as $image ): ?>
<div>
<div class="hero-gallery-slider-main__image">
<img />" alt="<?php echo esc_attr($image['alt']); ?>" height="<?php echo esc_attr($image['height']); ?>" />
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.