• Resolved trishahdee

    (@trishahdee)


    I’m using SearchAndFilter PRO with a custom post type created with Advanced Custom Fields. The custom results template was showing the search term until I started using Relevanssi and now the search term doesn’t show. I found the below code on your main website that works for category searches but my search does not use categories. The below code does show the number of results but not the term that was searched. Can you tell me the correct code to get the search term to display on the results page?
    query_vars['cat'] ); $s = $wp_query->query_vars['s']; echo $wp_query->found_posts . " results found with ' $s'"; if ( ! empty( $cat ) ) { echo " in the '$cat' category"; } ?>

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

    (@msaari)

    What are you using currently to display the search term? Relevanssi doesn’t change it: for example, the default get_search_query() in WordPress works exactly the same with or without Relevanssi. You can also get the search term from the global $wp_query->query_vars['s']. If anything, Search & Filter Pro is more likely to change this.

    Thread Starter trishahdee

    (@trishahdee)

    Thank you for your reply. The following template code works to show the search term but only when Relevanssi is NOT enabled in the Search & Filter Pro search form. When I turn Relevanssi on the the search term does not show. Do you still think it’s a Search & Find issue?

            <h1><?php
    printf(
    /* translators: %s: query term */
    esc_html__( 'Search Results for: %s', 'picostrap' ),
    '"' . get_search_query() . '"'
    );
    ?></h1>
    • This reply was modified 3 months, 1 week ago by trishahdee.
    • This reply was modified 3 months, 1 week ago by trishahdee.
    Plugin Author Mikko Saari

    (@msaari)

    Well, get_search_query() gets the search terms from $wp_query->query_vars['s'], and Relevanssi doesn’t touch that, so I don’t know how Relevanssi would break it. If enabling Relevanssi breaks this, then Relevanssi is somehow involved, but it must be partly related to Search & Filter, because Relevanssi in itself does not break this. Unfortunately, I don’t have Search & Filter, so I can’t investigate this further. All I can say is that this should work. Have you tried asking the S&F Pro support?

    Thread Starter trishahdee

    (@trishahdee)

    I am working with S&F Pro support and will report back if/when there is a solution.

    Thread Starter trishahdee

    (@trishahdee)

    Success! The tech at S&F said your comments pointed him in the right direction. The code for this can be found on this web page: https://searchandfilter.com/documentation/accessing-search-data/

    //Get the search term
    //replace "1526" with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1526)->current_query();
    echo $sf_current_query->get_search_term();

    Thank you for your help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.