diff --git a/src/ElementalSearchExtension.php b/src/ElementalSearchExtension.php index 9a78457..4ce97c3 100644 --- a/src/ElementalSearchExtension.php +++ b/src/ElementalSearchExtension.php @@ -37,10 +37,12 @@ public function onAfterUnpublish() public function updateSearchContent() { $parent = $this->getOwner()->getPage(); - //Even though we have the parent page. Lets always get the "live" version. This is so when we update the search content we are not indexing draft/unpublished content - $liveParentPage = Versioned::get_by_stage($parent->ClassName, Versioned::LIVE)->byID($parent->ID); - if ($liveParentPage && $liveParentPage->hasExtension(SiteTreeSearchExtension::class)) { - $liveParentPage->updateSearchContent(); + if ($parent) { + //Even though we have the parent page. Lets always get the "live" version. This is so when we update the search content we are not indexing draft/unpublished content + $liveParentPage = Versioned::get_by_stage($parent->ClassName, Versioned::LIVE)->byID($parent->ID); + if ($liveParentPage && $liveParentPage->hasExtension(SiteTreeSearchExtension::class)) { + $liveParentPage->updateSearchContent(); + } } } } \ No newline at end of file