I have a function set up in my App.php controller which I'm looking to pass to a Gutenberg block, but unfortunately its showing an error "Undefined variable: testimonial_loop in on line : invalid argument supplied for foreach() in on line" - as you will see on attached screenshot, I've added the same function and outputted through a non-Gutenberg blade template which works fine.Any idea why the block may be showing this error?
I have a function set up in my App.php controller which I'm looking to pass to a Gutenberg block, but unfortunately its showing an error "Undefined variable: testimonial_loop in on line : invalid argument supplied for foreach() in on line" - as you will see on attached screenshot, I've added the same function and outputted through a non-Gutenberg blade template which works fine.Any idea why the block may be showing this error?
public function testimonialLoop() { $testimonial_items = get_posts([ 'post_type' => 'testimonial', 'posts_per_page' => '-1' ]); return array_map(function ($post) { return [ 'title' => apply_filters('the_title', $post->post_title), 'content' => apply_filters('the_content', $post->post_content), 'thumbnail' => get_the_post_thumbnail($post->ID, 'large'), 'by' => get_field('testimonial_by', $post->ID), ]; }, $testimonial_items); }
which I'm trying to pass to a gutenberg block:
`{{-- Title: Testimonial Description: Customer testimonial Category: formatting Icon: admin-comments Keywords: testimonial quote Mode: edit Align: left PostTypes: page post SupportsAlign: left right SupportsMode: false SupportsMultiple: false EnqueueStyle: styles/style.css EnqueueScript: scripts/script.js EnqueueAssets: path/to/asset --}} @foreach($testimonial_loop as $item)
@php wp_reset_postdata() @endphp @endforeach ` Thanks