Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro conditional search results

Viewing 7 posts - 1 through 7 (of 7 total)
  • dann hanks
    #101346

    Hi,
    I am using search & filter with ACF, I am hoping to add conditional elements to the search results if the search is a particular string.

    Example, I have a dropdown menu automatically generated by ACF lets say the options are:

    Banana
    Apple
    Pear

    … if ‘Banana’ was selected then the search url would be something like:

    website.com/?sfid=132396&_sfm_fruit=1

    So on the search results page, I would like to show a picture of a banana, if I had selected Apple, an apple… you get the picture.

    I was hoping there would be some way to include this through some conditional code?

    thanks.

    Trevor Moderator
    #101424

    Yes. But the code may be complex. As long as you have access to the php page template for the results page, you can use the sf_query array to find the value and use that to conditionally show what you want by echoing HTML to the page.

    This thread discusses the technique for accessing the data:

    https://support.searchandfilter.com/forums/topic/results-displayed-results-count-searched-tag-associated-categories/

    dann hanks
    #101540

    Hi Trevor, thanks for your reply, I am a little confused though – I’m finding hard to decypher the code from your link and apply it to my case…

    website.co.uk/?sfid=132396&_sfm_department=14

    Would be my search string, this searches a particular ‘department’, I would like to show div based on this department.

    so my code would be somthing like:

    if url = ?sfid=132396&_sfm_department=14

    echo : “<div>welcome to department 14</div>”

    I have found a way to do this with jQuery, the only issue I have with this method though is it looks for a particular url so if I wanted to show for: ?sfid=132396&_sfm_department=1 dpartment 1’s div, it would also show for ?sfid=132396&_sfm_department=11, ?sfid=132396&_sfm_department=12 etc etc as it contains ?sfid=132396&_sfm_department=1

    Trevor Moderator
    #101543

    You could simply make 3 if statements in a row?

    dann hanks
    #101545

    Hi, I found a better code for triggering the jquery to kick in on the url so its working for 1, 11, 12 differently which is great.

    My only issue now is that I can’t execute php code within the jQuery which is why I wanted to do it on the search results page rather than through javascript. What I actually want to hide/show is featured posts dependant on the department searched for. It would be great if I can do this on the search reults template instead of achieving it through jQuery.

    : )

    Dann

    Trevor Moderator
    #101558
    This reply has been marked as private.
    dann hanks
    #101611

    Thanks for the Skype support Trevor! All sorted and running exactly the way I need it to.

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘conditional search results’ is closed to new replies.