0

We display all the entries on our site using a Super Search loop inside an embed called results.html which we embed on the main page on our site. These display our posts by default, instead of using a standard channel entries tag... (I think we originally took this approach as we were using AJAX searching, but we have since abandoned this and are just using standard searching now).

We're trying to make Super Search search multiple channels (Teachers, Schools and Zoo Visitor), but we only want to display results for two of these channels (Schools and Zoo Visitor) when keywords are being searched for. This is because we don't want to have a list of posts populated by the less important content from these channels, but we still want to keep the channels searchable.

We have managed to get this working by using the setup outlined below, and more specifically, the following condition allows us to detect if keywords have been searched for and

{if:elseif channel_name == 'schools' && segment_2 == "search&keywords={super_search_keywords}"}

and

{if:elseif channel_name == 'zoo_visitor' && segment_2 == "search&keywords={super_search_keywords}"}

This is working! However, at the last hurdle, we're running into a final problem where we get blank results when no search has been run (i.e. keywords). It seems the channels which we are ignoring when no search has been run because of the condition above (Schools and Zoo Visitor), seem to be being counted in the pagination.

So our first page of results contains one entry and then the second page has a whole load of entries from the Teacher channel etc...

How can we get round this and stop these channel results being counted in the pagination?

Thanks for your time!

--------------------- results.html ---------------------

{exp:super_search:results channel="teachers|schools|zoo_visitor" status="not closed" orderby="date" sort="desc" limit="29" author_indicator="screen_name" keyword_search_author_name="yes" paginate="bottom" status="Members-id5|Members_Verified_-id6|Members_Pro-id7|open"}

  {if super_search_no_results}
     Sorry, no results message...
  {/if}


  {if channel_name == 'teachers'}

  <article>

    {title}

  </article>


{if:elseif channel_name == 'schools' && segment_2 == "search&keywords={super_search_keywords}"}

      <article>

      {title}

      </article>

  {/if}


    {if:elseif channel_name == 'zoo_visitor' && segment_2 == "search&keywords={super_search_keywords}"}


      <article>

      {exp:zoo_visitor:details} 

      {member_lastname}

      {exp:zoo_visitor:details}

      </article>

  {/if}


{paginate}
Page {current_page} of {total_pages} &nbsp; {pagination_links}
{/paginate}


{/exp:super_search:results}

1 Answer 1

0

Summary: display searched entries from 3 channels if a keyword search was conducted, and display entries from 2 channels if keyword search was not conducted yet.

There may be other solutions, but one way could be to use {super_search_keywords} in a conditional to control both situations. You could, for example:

{if super_search_keywords == ""}
    {exp:super_search:results channel="channel_1|channel_2"}
        // Your data
    {/exp:super_search:results}
{/if}

{if super_search_keywords != ""}
    {exp:super_search:results channel="channel_1|channel_2|channel_3"}
        // Your data
    {/exp:super_search:results}
{/if}

Since you can use {super_search_keywords} inside {exp:super_search:results} as well (see http://www.solspace.com/docs/super_search/results/#variables), you could do this:

{exp:super_search:results channel="channel_1|channel_2|channel_3"}
    {if super_search_keywords == ""}
        // Your conditionals for channels 1 & 2
        // No need for a funky conditional for checking segment_2
    {/if}

    {if super_search_keywords != ""}
        // Your conditionals for channels 1 & 2 & 3
        // No need for a funky conditional for checking segment_2
    {/if}
{/exp:super_search:results}

Other {exp:super_search:results} parameters were omitted above for clarity.

1
  • Thank you so much - The top answer worked and made for a much cleaner, lighter solution too! (The second answer didn't because it still searches all three channels it generates the blank results that appear to count towards the pagination)
    – jx3
    Sep 23, 2014 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.