ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Access Search Parameters from Results Page

April 11, 2012 12:34am

Subscribe [1]
  • #1 / Apr 11, 2012 12:34am

    timothyhellwig

    5 posts

    Hi folks,

    On my search form, I have a setup where users can restrict a search to a certain channel. For example, while a plain search would pull results both from the News channel and from the Events channel, a user can select to search only in the News channel or only in the Events channel.

    I have this search-filter part working, and am able to display the filtered results fine.

    My problem is that I need to be able to access from the search results page the name of the channel that the user chose to filter by.
    This is so that I can print something like, “Showing results only from [channel name]” to the screen for the user’s convenience.

    Does anyone know how to do this?

    Thanks in advance!

    —Timothy

  • #2 / Apr 11, 2012 12:45pm

    Dan Decker

    7338 posts

    Hi Timothy!

    Welcome to ExpressionEngine and the Forums! It’s nice to have you here!

    Indeed, as noted in the User Guide on Search Results:

    Nearly all of the Channel Entries Tag Variables are available for the search results page so that you can display as much or as little of the channel entry’s data as possible depending on your needs…

    With that, you should be able to use something similar to this:

    exp:search:search_results}
    
       Showing results only from {channel}
    
    --- your results template code ---
    
    {/exp:search:search_results}

    Let me know if you have any other questions!

    Cheers,

  • #3 / Apr 11, 2012 10:14pm

    timothyhellwig

    5 posts

    Hi Dan,

    Thanks for your fast reply. Unfortunately, the {channel} tag doesn’t produce the result I need. Here’s why:

    {exp:search:search_results} loops through all the search results, so the {channel} tag actually returns the channel for the individual entry that is being looped through, rather than the channel that all the search results were filtered by.

    For example, the following code will only print out the channel of the first search result.

    {exp:search:search_results limit="1"}
    
       Showing results only from {channel}
    
    --- your results template code ---
    
    {/exp:search:search_results}

    This is fine if the results are filtered so that only one channel is being shown, but the users on my site also have the option to not filter the search by any channel, and in this case, the channel of the first search result will not be an accurate representation of all the rest of the search results.

    Do you see the dilemma I’m running into here?
    Let me know if you have any other ideas.

    Thanks for your help!

  • #4 / Apr 12, 2012 5:50pm

    Dan Decker

    7338 posts

    Hi Timothy,

    Ok, this is a bit of a stretch…

    With your channel selection menu, you are passing the channel ID to the search results page. That is only so useful, but it gives us a place to start!

    That value will be in the $_POST array, but to get that, you will need to use PHP in your results template. Let’s avoid that.

    So, 2 add-ons to the rescue!
    EvoPost will let you get the value of channel_id from the $_POST array and Blog Info will allow you to turn that number into useful text/info about the channel that was selected.

    Let me know if you have any other questions!

    Cheers,

  • #5 / Apr 12, 2012 8:13pm

    timothyhellwig

    5 posts

    Great, I’ve been too busy today to try this yet, but that looks like exactly what I need. I’ll post back once I give it a try.

    Thanks Dan!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases