Grab Taxonomy name rather than ID in custom search
-
Hey all!
So, I’m coding my first search filtering system from scratch. I was originally using the Search & Filter plugin, which works like a dream, however with the way in which my client want to style the dropdowns and wire the search differently on certain pages, we’ve decided to nix the usage of plugins and opt in for coding something with just the bare minimum of what we need to get this working.
That being said, I have a custom post type called “brands” and am currently working to add a handful of custom taxonomies via dropdowns so users may filter their search with ease. I’m really close to getting the code to work, however for whatever reason my current code seems to be grabbing the taxonomy term ID rather than its actual name and applying it to the search.
So, if I am searching by brand location- and I select “California” from the location dropdown, then type clothing- the search url *should* render as
https://www.mywebsite.com/?brand-location=california&s=clothing&post_type=brands
instead- what I’m getting is
https://www.mysite.com/?brand-location=48&s=clothing&post_type=brands
Which obviously displays a “Nothing Found” page as well as a drop of table-flipping rage for myself :p
I’m currently using this code within the search form to display my state location dropdown:
<?php $args = array('taxonomy' => 'brand-location', 'hide_empty' => 1, 'echo' => 1, 'name' => 'brand-location' ); if (isset($_GET['brand-location'])){ $args['selected'] = intval($_GET['brand-location']); } wp_dropdown_categories( $args );?>
I’m moderately new to PHP, and I’m sure the solution is fairly simple and will make me feel like an uber-n00b for not figuring it out sooner, but I’ve done quite a few searches at this point and can’t seem to find an answer that isn’t someone recommending the use of a plugin instead.
Any ideas or help would be appreciated!
- The topic ‘Grab Taxonomy name rather than ID in custom search’ is closed to new replies.