1

I am currently switching my site from the Simple Search Form to the Advanced Search Form. I would like to allow my users to search on the Categories for one channel. I used the example code provided in the documentation. I would really like to remove the "Channels" section on the search. I know I want to search one Channel (News). With the built Search module is there a way to do the multi-select on the category without the multi-select on the Channel?

I included a screenshot of what my search currently looks like and the code of the search template.

Thanks for your help!!!

enter image description here

{exp:search:advanced_form channel="news" search_in="entries" form_class="search-form" result_page="newsroom/results" results="12"}

<fieldset>
 <legend>{lang:search_by_keyword}</legend>
 <div class="search-keywords">
   <p>
     <label for="advancedKeywords">Keywords</label>
     <input type="text" name="keywords" id="advancedKeywords" value="">
   </p>
 </div>
 <div class="search-channels">
   <p>
     <label for="channel_id">{lang:channels}</label>
     <select id="channel_id" size="2" name="channel_id[]" onchange="changemenu(this.selectedIndex);">
         {channel_names}
     </select>
   </p>
 </div>
 <div class="search-categories">
   <p>
     <label for="categories_id">{lang:categories}</label>
         <select id="categories_id" name="cat_id[]" size="4"  multiple="multiple" style="width:154px;">
             <option value='all' selected="selected">{lang:any_category}</option>
     </select>
   </p>
 </div>
</fieldset>
<fieldset>
 <legend >Dates and sorting</legend>
 <div class="date">
   <select name="date">
     <option value="0" selected="selected">{lang:any_date}</option>
     <option value="7">{lang:this_week_and}</option>
     <option value="30">{lang:one_month_ago_and}</option>
     <option value="90">{lang:three_months_ago_and}</option>
     <option value="180">{lang:six_months_ago_and}</option>
     <option value="365">{lang:one_year_ago_and}</option>
   </select>
   <div class="date_order">
     <input type="radio" name="date_order" value="newer" id="newer" class="radio" checked="checked">
     <label for="newer">{lang:newer}</label>
     <input type="radio" name="date_order" value="older" id="older" class="radio">
     <label for="older">{lang:older}</label>
   </div>
 </div>
</fieldset>
<input type="submit" value="Search" class="button news-button">
{/exp:search:advanced_form}
2
  • Sorry, the code did not turn out in the post. Here is the portion I was referencing: <select id="channel_id" size="2" name="channel_id[]" onchange="changemenu(this.selectedIndex);"> {channel_names} </select> <select id="categories_id" name="cat_id[]" size="4" multiple="multiple"> <option value='all' selected="selected">{lang:any_category}</option> </select>
    – Emily M
    Apr 12, 2019 at 1:56
  • Hi Emily, you should be able to edit your own question soon, if not already.
    – Alex Kendrick
    Apr 16, 2019 at 16:18

1 Answer 1

0

Ok, so this isn't really that hard. What you need to do is drop the auto generation of the select field for your form and just hard code the channel id you want to be passed to the search. This may need some tweaking to get working, but the idea is correct.

You will need to determine the channel id of your news channel to move forward. This example assumes the your news channel id is 123. First, remove the generation of the select for channel from your code. So remove this line:

{lang:channels} {channel_names}

and in it's place, use this line:

<input type="hidden" id="channel_id" name="channel_id" value="123" />

Just replace 123 with whatever the actual id of your channel is. That should do it.

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.