How to *actually* output the search results title

Forums › Forums › Search & Filter Pro › How to *actually* output the search results title

Viewing 3 posts – 1 through 3 (of 3 total)
  • Anonymous
    #184498

    Hi guys.

    I’ve been here to support to ask why I can’t simply print the search results title, and also talked via skype to someone in support about the issue.

    I got pointed to your official bit about it, which simply outputs “search results” on the page rather than any info about what was sorted: https://searchandfilter.com/documentation/search-results/as-an-archive/#update-page-title

    And also down some rabbit hole about SEO plugins.

    I’ve got a simple solution here that I’d really love to see you put in the developer docs so that other people can solve this problem for what should be a core / simple feature.

    The idea is to retrieve the search parameter that’s getting passed to the search results page from the URL, and check that it isn’t empty:
    =isset($_GET['NAME_OF_URL_SEARCH_PARAMETER']) ? $_GET['NAME_OF_URL_SEARCH_PARAMETER'] : "";

    and pass that parameter to a new variable.

    <?php $name_of_variable = isset($_GET['NAME_OF_URL_SEARCH_PARAMETER']) ? $_GET['NAME_OF_URL_SEARCH_PARAMETER'] : ""; ?>

    Now that that we have $name_of_variable, we can echo it to print it on the page.
    <h2>Search results for <?php echo $name_of_variable; ?></h2>

    If there are multiple variables being searched, rinse and repeat.

    So my code that works for my 4-dropdown search form results page looks like:

    <?php $speaker_name = isset($_GET['_sfm_speaker_name']) ? $_GET['_sfm_speaker_name'] : ""; ?>
    <?php $fee_range = isset($_GET['_sfm_fee_range']) ? $_GET['_sfm_fee_range'] : ""; ?>
    <?php $state = isset($_GET['_sfm_state']) ? $_GET['_sfm_state'] : ""; ?>
    <?php $country = isset($_GET['_sfm_country']) ? $_GET['_sfm_country'] : ""; ?>
    
    Search Results for <?php if (!empty($speaker_name)) {
    	echo $speaker_name; 
    } ?>
    <?php if (!empty($fee_range)) {
    	echo $fee_range; 
    } ?>
    <?php if (!empty($state)) {
    	echo $state; 
    } ?>
    <?php if (!empty($country)) {
    	echo $country; 
    } ?>

    the !empty might be extraneous but it prevents errors.

    I hope this helps someone / I hope you include this in the docs, as this is a key thing to be able to do.

    Anonymous
    #184499

    If it helps clarify for people coming after, the parameter name comes from the search page url. so in my example http://mysite.com/search/?_sfm_state=California, someone has searched by the state of California. I’m checking in the php if _sfm_state is set, and if it is set (“isset”), I’m saving the value “california” to the new variable $state.

    Trevor
    #184509

    Thank you for sharing. I will pass this along to Ross, the developer.

Viewing 3 posts – 1 through 3 (of 3 total)

Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.