1

I am using a simple:search form in the site footer to search specific channels and display results in search/results, but have not successfully been able to organize them per channel as of yet. Here is my search form:

{exp:search:simple_form channel="careers|leadership|news|product_entries|partner_entries|video|case_studies" search_in="entries" where="all" name="footer_search" result_page="search/results" no_result_page="search/no-results" status="not closed"}
        <input type="text" name="keywords" value="KEYWORDS" onclick="this.select()" id="search" />
        <input type="submit" class="button" value="Search &raquo;" />
{/exp:search:simple_form}

Here is my results code in search/results:

<section>
        {exp:search:search_results orderby="channel_short_name" sort="asc"}             
            <h4>{if "{channel_short_name}" == "news"}News & Press{if:else}{channel}{/if}</h4>
            <p><a href="{if page_url}{page_url}{if:else}{auto_path}{/if}">{title}&nbsp;&raquo;</a></p>
        {/exp:search:search_results}
</section>

This produces results that don't actually order by the channel name, because partner_entries and products will randomly display in the middle of a chunk of news results. This was the only way of ordering search results that I could find, and would like to be able to produce an organized outcome similar to the following example:

Results for {exp:search:keywords}:

News & Press
------------
- {title}
- {title}
- {title}
- {title}
- {title}

Products
--------
- {title}
- {title}
- {title}
- {title}
1

The short answer is that you cannot sort by channel natively.

The long answer is that native search result ordering is determined by the search form itself so that the sorting can be done by the database when the search takes place. If an orderby field is present in the POST data, the sort can be customized with the following options:

<select name="orderby">
    <option value="date" >Entry Date</option>
    <option value="title" >Title</option>
    <option value="most_comments" >Most Comments</option>
    <option value="recent_comment" >Most Recent Comment</option>
</select>

You can set the order ascending or descending by including a sort_order input field set to the value of asc for ascending or desc for descending order.

Note that either of these can be set with hidden inputs if you like, but again, channel_short_name isn't an available sorting option (current as of v2.8.1).

3
  • Ahh, so those are the only 4 orderby options available by default? I suppose I could try to display the results a different way. Does {exp:search:search_results} allow nesting of an {exp:channel:entries} tag? I could display separate blocks for each channel that gets searched, or something. It would be messy behind the scenes, but it would look nicer to the user than what currently shows. Jun 5 '14 at 0:24
  • You could if you were careful, maybe by using an embed to construct the Channel Entries tag, feeding it the entry id's. This answer uses a similar construction method. Jun 5 '14 at 15:37
  • Thank you, I will test a few methods and post the solution if I find a good one. Jun 5 '14 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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