From d354915f29f7f14508001358495f7359607e43c2 Mon Sep 17 00:00:00 2001 From: Iain Date: Fri, 26 Apr 2019 11:57:08 +0100 Subject: [PATCH] Fix PHP Notice: Trying to get property of non-object, where the post ID saved in ACF referred to a deleted post. --- src/PostType/Testimonial.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/PostType/Testimonial.php b/src/PostType/Testimonial.php index 2438077..f45aa31 100644 --- a/src/PostType/Testimonial.php +++ b/src/PostType/Testimonial.php @@ -206,7 +206,12 @@ public static function fetch_by_section( $section, $post_id = false ) { $testimonials = ACF::get_repeater_field( $section, array( 'testimonial' ), $post_id ); foreach ( $testimonials as $testimonial ) { if ( is_array( $testimonial ) && isset( $testimonial['testimonial'] ) ) { - $all_testimonials[] = new \DeliciousBrains\WPTestimonials\Model\Testimonial( $testimonial['testimonial'] ); + $testimonial_object = new \DeliciousBrains\WPTestimonials\Model\Testimonial( $testimonial['testimonial'] ); + if ( ! isset( $testimonial_object->name ) ) { + continue; + } + + $all_testimonials[] = $testimonial_object; } }