Adding search
-
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://www.ads-software.com/plugins/beautiful-taxonomy-filters/
- The topic ‘Adding search’ is closed to new replies.