Skip to content

Mirasvit Sphinx Search indexing Magefan Blog – Error: Call to a member function setData() on bool

I am using the Mirasvit sphinx search and have configured an index from Magefan Blog posts. I get the following error in search result page regarding the blog posts.

<ul class="mst-search__result-tabs">
    <div class="mst-search__index mst-search__index-magefan-blog-post">
    <div class="post-list-wrapper">
        <ol class="post-list">
                                        <li>
Error: Call to a member function setData() on bool in /var/www/html/domain.com/html/app/design/frontend/Olegnax/athlete2/Magefan_Blog/templates/post/list/item.phtml:77

I saw that the sphinx extension calls the following post.phtml

<?php
//@codingStandardsIgnoreFile
/** @var MirasvitSearchBlockIndexBase $block */

/** @var MagefanBlogBlockPostPostListItem $postItem */
$postItem = $this->getLayout()->createBlock('MagefanBlogBlockPostPostListItem');
?>
<div class="mst-search__index mst-search__index-magefan-blog-post">
    <div class="post-list-wrapper">
        <ol class="post-list">
            <?php /** @var MagefanBlogModelPost $post */ ?>
            <?php foreach ($block->getCollection() as $post): ?>
                <li>
                    <?= $postItem
                        ->setPost($post)
                        ->setTemplate('post/list/item.phtml')
                        ->toHtml()
                    ?>
                </li>
            <?php endforeach ?>
        </ol>
    </div>
</div>

I guess my custom theme overrides the default Magefan block which the Mirasvit search calls and is missing. Part of my theme item.phtml is the following

<?php
/**
 * Blog post list item template
 *
 * @var $block MagefanBlogBlockPostAbstractPost
 * 
 * @category    Olegnax
 * @package     Olegnax_Athlete2
 * @copyright   Copyright (c) 2021 Olegnax (http://www.olegnax.com/)
 * @license     https://www.olegnax.com/license
 */

    $at_settings = $this->helper('OlegnaxAthlete2HelperHelper')->getConfig('athlete2_settings/blog');
    $_post = $this->getPost();
    $_postClasses = [];
    $_postClassesOutput ='';
    $_postClasses[] = 'post-holder';
    $_postClasses[] = 'post-holder-' . (int)$_post->getId();
    if($_post->getData('ox_post_list_style')){
        $_postClasses[] = 'post-style--' .  $block->escapeHtmlAttr($_post->getData('ox_post_list_style'));
    }
    $_postUrl = $block->escapeUrl($_post->getPostUrl());
    $_postName = $block->escapeHtml($_post->getTitle(), null, true);    
    $_styleClassic = $at_settings['blog_style_classic'];
    $_hideReadMore = $at_settings['blog_list_read_more'];
    $_hideCommentsLink = $at_settings['blog_list_comments_link'];
    $_hideAuthor = $at_settings['blog_list_author'];
    $_hideDate = $at_settings['blog_list_date'];
    $_hideCategories = $at_settings['blog_list_categories'];
    $iBigWidth = $at_settings['blog_list_big_image_width'];
    $iBigHeight = $at_settings['blog_list_big_image_height'];
    $iWidth = $at_settings['blog_list_image_width'];
    $iHeight = $at_settings['blog_list_image_height'];
    $imgAttrs ='';
    $imgBigAttrs ='';
    if($iBigWidth ) {
        $imgBigAttrs ='width="' . $iBigWidth . '"';
    }
    if($iBigHeight) {
        $imgAttrs ='height="' . $iBigHeight . '"';
    }
    if($iWidth ) {
        $imgAttrs ='width="' . $iWidth . '"';
    }
    if($iHeight) {
        $imgAttrs ='height="' . $iHeight . '"';
    }
    $hide_desc = $at_settings['description'];
    $expand = $at_settings['description_expand'];
    $maxheight = $at_settings['description_expand_height'];
    $metaContent = '';
    $metaContentModern = '';
    if($iWidth && $iHeight) {
        $featuredImage = $_post->getFeaturedImage([$iWidth, $iHeight]);
    } else {
        $featuredImage = $_post->getFeaturedImage();
    }
    if($iBigWidth && $iBigHeight) {
        $bigFeaturedImage = $_post->getFeaturedImage([$iBigWidth, $iBigHeight]);
    } else {
        $bigFeaturedImage = $_post->getFeaturedImage();
    }
    $_dateOnImage = $at_settings['blog_list_date_image'];
    $_listStyle = $at_settings['blog_list_style'];
    $dateMonth = $block->escapeHtmlAttr($_post->getPublishDate('F'));
    if(strlen($dateMonth) > 4){
        $dateMonth = $block->escapeHtmlAttr(substr($dateMonth, 0, 3));
    }
    if($_dateOnImage){
        $_postClasses[] = 'date-above-image';
    }
    if(!empty($_postClasses)){
        $_postClassesOutput = 'class="' . implode(' ',  $_postClasses) . '"';
    }
    
    if ( !$_hideCommentsLink ) { 
        $metaContent .= $this->getChildBlock( "blog.post.ox_comments_link" )->setData('post', $_post )->toHtml();       
    } 

What should I change or add to fix the error in search results?