• Tom

    (@esilverstrike)


    I notice when I do the Admin search that is shows a snippet of the matching text for the pages that it returns in the search results.

    Is this possible to do on the WordPress Search Results page?

    I am using Bricks Builder and have the search query setup for the search template. Is there some sort of dynamic data field I can reference or even a PHP function I can call in the query loop to return the string?

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

    (@msaari)

    The default the_excerpt() function in WordPress should show the Relevanssi-generated excerpt. I don’t know if Bricks affects that somehow. The Relevanssi excerpt is also in $post->post_excerpt.

    Plugin Author Mikko Saari

    (@msaari)

    I found this in my email from last summer as a fix for Relevanssi excerpts in Bricks:

    function brx_relevanssi_excerpt_workaround() {
        global $post;
        return relevanssi_do_excerpt( $post, get_search_query() );
    }

    If this doesn’t work, ask Bricks support – they’re familiar with Relevanssi and can probably help you.

    Thread Starter Tom

    (@esilverstrike)

    Thanks for the reply. So I can retrieve the post excerpt using dynamic data which does highlight any text that happens to be in the actual post excerpt.

    What happens is the text is somewhere else like in a custom field or post content. Does the sentence with the match text get moved to the post excerpt by Relevanssi or can I retrieve this matching sentence some how?

    After doing more testing it looks like the Admin search only returns excerpts if they actually exist for the post… I had thought it returned text from any part of the post if matching text was found.

    Plugin Author Mikko Saari

    (@msaari)

    If the relevant setting is enabled, Relevanssi generates custom excerpts from the post content (and custom fields; this is controlled by the Relevanssi excerpt settings). Since Bricks doesn’t use post content and instead stores everything in custom fields, you must ensure Relevanssi is set to use custom fields in the excerpts.

    Anyway, these are Bricks problems and I’m not good with Bricks. Try asking the Bricks support; they’re better with Relevanssi than I am with Bricks.

    Thread Starter Tom

    (@esilverstrike)

    Thanks for your help. I found the custom fields setting for excerpts in Relevanssi. This is perfect.

    One issue I found is it also looks like on queries with pagination, excerpts for those posts on page 2+ or load more are missing the auto excerpts.

    Disabling Relevanssi plugin and those missing excerpts on page 2+ are then again displayed. This happens on the search page and blog post page. (the only ones I have to test with)

    Could this be a Relevanssi bug or more Bricks?

    I’ll open an issue with Bricks as well.

    • This reply was modified 9 months, 3 weeks ago by Tom.
    Plugin Author Mikko Saari

    (@msaari)

    That’s some combination of Relevanssi and Bricks. Relevanssi in general has no problems creating excerpts for the second page of search results. Depending on how the results are loaded, they may or may not come from Relevanssi.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Showing Matching Text in WordPress Search Results Page’ is closed to new replies.