Title: Adding search
Last modified: August 22, 2016

---

# Adding search

 *  Resolved [folbert](https://wordpress.org/support/users/folbert/)
 * (@folbert)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/adding-search-3/)
 * Thank you for a great plugin that did exactly what I was looking for.
 * This isn’t a question but I just wanted to let anyone else coming here looking
   for how to add search to the filter know how I got it to work using these easy
   steps (maybe there’s an even easier or more future proof way of doing it?). Maybe
   it could be implemented as a feature?
 * Since we need to add a text field to the form and in my case I also needed more
   control over the layout of the form, I created a copy of beautiful-taxonomy-filters-
   public-display.php and added this to the top of the original file:
 *     ```
       <?php
       require_once(get_template_directory() . '/templates/custom-filter.php');
       return;
       ```
   
 * Then in custom-filter.php, I added a text field:
 * `<input type="text" name="s" value="<?php echo isset($_GET['s']) ? $_GET['s']:'';?
   >" />`
 * And finally, right before $new_url = $this->append_get_parameters($new_url); 
   in public/class-beautiful-taxonomy-filters-public.php, I added this:
 *     ```
       if(isset($_POST['s'])) {
         if (empty($_POST['s'])) {
          unset($_GET['s']);
         } else {
           $_GET['s'] = $_POST['s'];
         }
       }
       ```
   
 * Yes, I had to edit the code of the plugin, which of course is not wise to do 
   since it will be overwritten when updating the plugin, but I found no other way
   of doing this.
 * If you have the standard search field and the filter on the same page, both search
   fields will be populated with the value of s, but in my case that is not an issue
   and I assume that there are ways around that if needed.
 * [https://wordpress.org/plugins/beautiful-taxonomy-filters/](https://wordpress.org/plugins/beautiful-taxonomy-filters/)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [Jonathandejong](https://wordpress.org/support/users/jonathandejong/)
 * (@jonathandejong)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/adding-search-3/#post-5771636)
 * Hi Folbert,
 * I’ve implemented search on a site myself along with this plugins filters. However
   since the “s” parameter sent the user to the search result page (might be different
   now) I added it as a custom parameter “search” instead keeping the user on the
   archive page.
 * In any case. There should be a few things to consider here. There are actions
   sprinkled throughout the plugin which you can use to add your input field.
 * if you want the search field to be inside the form you can use either
    `beautiful_actions_beginning_form`
   or `beautiful_actions_ending_form` and if you’d rather have it outside the form
   with its own submit button (but still inside the filter module) you can use `
   beautiful_actions_before_form` or `beautiful_actions_after_form`.
 * As for the second part of your solution there’s no action to use at the moment
   but I could easily add one inside that function so you wouldn’t have to modify
   the core files. Or you could just add your own template_redirect filter with 
   a priority lower than 10.
 *     ```
       function the_search_redirect(){
   
       	if(isset($_POST['s'])) {
       	  if (empty($_POST['s'])) {
       		   unset($_GET['s']);
       		  } else {
       		    $_GET['s'] = $_POST['s'];
       		}
       	}
   
       }
       add_filter('template_redirect', 'the_search_redirect', 9, 1);
       ```
   
 *  Plugin Author [Jonathandejong](https://wordpress.org/support/users/jonathandejong/)
 * (@jonathandejong)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/adding-search-3/#post-5771637)
 * I just tried it on my dev site and seem to work the same so in doing like my 
   suggestion you wont have to modify plugin files 🙂
 *  Thread Starter [folbert](https://wordpress.org/support/users/folbert/)
 * (@folbert)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/adding-search-3/#post-5771654)
 * Great. Thanks for the tip about template_redirect.
 * I had no problems using the s-parameter (I placed the text field in the same 
   form as the taxonomy-drop-downs). But your input gave me the idea to use the 
   posts_where filter so I could get even more control over what is searched when
   the text field is filled out. That way I can also rename the text field to whatever
   i like.
 * So now, an URL like “[http://site.void/medarbetare/position/position-1/kontor/malmo/?namn=xavier&#8221](http://site.void/medarbetare/position/position-1/kontor/malmo/?namn=xavier&#8221);
   works just as expected.
 * I saw the actions enabling me to put elements in the form but I think that I 
   will need even more control over the html in the form. Will keep it in mind though.
 * Thank you again for your work with the plugin.
 *  Plugin Author [Jonathandejong](https://wordpress.org/support/users/jonathandejong/)
 * (@jonathandejong)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/adding-search-3/#post-5771674)
 * Yepp that’s pretty much exactly how I use it too except with a custom search 
   function using relevanssi 🙂
 * In what way do you need more control over the HTML?
 *  Thread Starter [folbert](https://wordpress.org/support/users/folbert/)
 * (@folbert)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/adding-search-3/#post-5771685)
 * The major “issue” is that I need the text field to appear right before the submit
   button. I want to avoid using CSS to change the order of things since it would
   make no sense for users of screen readers to have the submit button appear before
   the text field.
 * I do understand that it is impossible to implement actions for every use case
   out there 🙂
 *  Plugin Author [Jonathandejong](https://wordpress.org/support/users/jonathandejong/)
 * (@jonathandejong)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/adding-search-3/#post-5771707)
 * Ah I see..
 * Well in a way it makes sense to be able to add input either at the beginning 
   of the inputs or just before the submit button.
 *  Plugin Author [Jonathandejong](https://wordpress.org/support/users/jonathandejong/)
 * (@jonathandejong)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/adding-search-3/#post-5771805)
 * Hey,
 * Just letting you know that there’s now more actions to add your own inputs/html
   to the filter module. you might like the new “beautiful_actions_before_submit_button”
   action or the “beautiful_actions_ending_form_inner”.
 * There is also a new action inside the plugins redirect_template function
    “beautiful_actions_before_redirection”
   which occurs before the append_get_parameters function (so you can use that instead
   of a custom template_redirect function or modifying the plugin files.
 * In short, you should be able to do what you need now without modifying plugin
   files 🙂
 *  Thread Starter [folbert](https://wordpress.org/support/users/folbert/)
 * (@folbert)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/adding-search-3/#post-5771846)
 * 🙂 Thank you for adding these actions.
 * Will update and try them out immediately.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Adding search’ is closed to new replies.

 * ![](https://ps.w.org/beautiful-taxonomy-filters/assets/icon-256x256.png?rev=1654967)
 * [Beautiful taxonomy filters](https://wordpress.org/plugins/beautiful-taxonomy-filters/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/beautiful-taxonomy-filters/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/beautiful-taxonomy-filters/)
 * [Active Topics](https://wordpress.org/support/plugin/beautiful-taxonomy-filters/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/beautiful-taxonomy-filters/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/beautiful-taxonomy-filters/reviews/)

## Tags

 * [filter](https://wordpress.org/support/topic-tag/filter/)
 * [taxonomy](https://wordpress.org/support/topic-tag/taxonomy/)

 * 8 replies
 * 2 participants
 * Last reply from: [folbert](https://wordpress.org/support/users/folbert/)
 * Last activity: [11 years, 3 months ago](https://wordpress.org/support/topic/adding-search-3/#post-5771846)
 * Status: resolved