I have a slideshow that is pulling in content from an ACF repeater field. This is working fine and I’ve been able to grab most of the data and display in the template. But I’ve had to add a ACF relationship field within the repeater field that pulls in content from a custom post type.
I’m new to Sage and not the strongest when it comes to PHP.
I’m having trouble working out how to pull out the correct content from the relationship field within my controller. The ‘caseStudy’ is the relationship field.
Here’s my original controller:
public function slideshow() {
// Initialize the return variable
$data = '';
// Get the appropriate hero
$slideshow = get_field('slideshow_home');
if(is_array($slideshow)) {
foreach( $slideshow as $p ) {
$data .= \App\template('partials.front-page.slide-item', [
'title' => $p['slideshow_home_main_title'],
'shortTitle' => $p['slideshow_home_short_title'],
'intro' => $p['slideshow_home_intro'],
'btnText' => $p['slideshow_home_button_text'],
'link' => $p['slideshow_home_button_link'],
'video' => $p['slideshow_home_video'],
'poster' => $p['slideshow_home_poster'],
'caseStudy' => $p['slideshow_case_study'],
]
);
}
}
// Always return
return $data;
}
I’m using the relationship field by itself elsewhere to get the same sort of content but not inside a repeater field:
public function related() {
global $post;
$data = [];
$related_case_studies = get_field('featured_case_study');
foreach ($related_case_studies as $p) {
$this_post = (object) array(
'thumbnail' => get_the_post_thumbnail_url($p, 'full'),
'permalink' => get_the_permalink($p),
'title' => get_the_title($p),
);
array_push($data, $this_post);
}
return $data;
}
Do I just need a foreach loop within the caseStudy section?
In my blade template I have an intro-slider with this:
@if( $slideshow )
<div class="intro-slideshow">
{!! $slideshow !!}
</div>
@endif
The a slide-item template with this:
<div class="intro-slideshow__wrapper">
<div class="intro-slideshow__content">
<h1 class="intro-slideshow__title">{{ $title }}</h1>
<p class="intro-slideshow__intro">{{ $intro }}</p>
<p class="intro-slideshow__btn"><a class="btn" href="{{ $link }}>{{ $btnText }}</a></p>
// case study content should go here
</div>
<source src="{{ $video }}" type="video/mp4">
</video>
</div>
Any help would be greatly appreciated!
John