• Resolved brocatus

    (@brocatus)


    On the search results page I show a sidebar with the latest posts. This is a standard sidebar that I show throughout the site. However on the search results page if one of these posts matches the search query: the excerpt is being replaced with the relevanssi generated excerpt and the search term highlighted. This messes up my formatting / design. Is there a way to make the sidebar NOT use the relevanssi excerpt on the search results page? I tried to include a wp_reset_query before getting the sidebar, but that did not help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Relevanssi replaces the excerpt in the post object with the excerpt it creates. The original excerpt is stored in the post object in the attribute $post->original_excerpt. The sidebar fetches the post from cache, where the excerpt has been replaced.

    So, couple of possible solutions here:

    – Clear the post object cache before the sidebar, ie. run clean_post_cache() for all the posts in the search results loop.
    – Replace $post->post_excerpt with $post->original_excerpt for all posts in the search results loop.

    Thread Starter brocatus

    (@brocatus)

    Thank you very much!

    Adding <?php clean_post_cache( get_the_ID() ); ?> at the end of the search results loop solved my problem!

    Your other solution I could not use as I use a plugin to display the sidebar posts and did not want to change that code.

    Thread Starter brocatus

    (@brocatus)

    For later reference:

    <div class="search-result">
        <?php while ( have_posts() ) { the_post(); ?>
    	<a href="<?php echo get_permalink(); ?>">
          	<h3><?php relevanssi_the_title();  ?></h3>
    	<?php  the_excerpt() ?>
    	</a>
    	<?php clean_post_cache( get_the_ID() ); ?>
        <?php } ?>
    </div>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘relevanssi-generated excerpt showing up in sidebar posts’ is closed to new replies.