Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Filter against custom taxonomy
- This topic has 15 replies, 3 voices, and was last updated 12 years, 3 months ago by
webmarketingmaster.
-
AuthorPosts
-
November 6, 2013 at 3:26 pm #781
iltdev
ParticipantI have a custom post-type of ‘event’ which contains a custom taxonomy of ‘event-categories’.
I need to limit the search to the event category id 43 and all its children. Is this possible?November 6, 2013 at 8:39 pm #782Ernest Marcinko
KeymasterHi!
Unfortunately it is not possilbe. Filtering by custom taxonomies in custom post types is not implemented. Many customers asked for it, but I still couldn’t find a solution.
November 7, 2013 at 8:39 am #784iltdev
ParticipantHi,
That’s a shame. Hopefully there will be a solution for a future version of the plugin.
I’ve written a search just for my needs using tax_query.February 11, 2014 at 1:56 pm #949webmarketingmaster
ParticipantHas anyone figured this out yet? I also want to search in custom categories. If you can give us some guidance, maybe we can customize the plugin to achieve this goal.
February 11, 2014 at 3:04 pm #951Ernest Marcinko
KeymasterActually it’s now possible with the 2.0 version 🙂
On the new demo site you can see a WooCommerce example, where the results are filtered by product categories (which is a custom taxonomy)
If you already bought the search earlier, you can download it again from codecanyon.
If you haven’t and you need to check the compatibility with another plugin, you can let me know here. This site is still a little messy, I can hopefully make a pre-sales question form soon 🙂
February 11, 2014 at 4:23 pm #959webmarketingmaster
ParticipantGreat News!! Im going to buy your plugin right now!
Thanks for the prompt response.
February 12, 2014 at 12:59 pm #964webmarketingmaster
ParticipantIm running into a problem. I NEED the taxonomy to SHOW UP as the SEARCH RESULT and be clickable. How do I accomplish this?
February 12, 2014 at 1:09 pm #965webmarketingmaster
ParticipantOne more comment. i dont want to FILTER by taxonomies, I want to show the taxonomies as the ACTUAL search results.
Is this possible with the current plugin or would we need to customize the plugin?
thanks
-
This reply was modified 12 years, 3 months ago by
webmarketingmaster.
February 12, 2014 at 1:22 pm #967Ernest Marcinko
KeymasterHi!
Not possible in the current plugin state. I’m looking for a solution if there is an easy way to achieve this by modifications. Actually returning taxonomies as search results is maybe an extra 100 lines of code or less. The problem is to fabricate the url, where these results would lead the user. Apparently the url structure is something like yoursite.com/index.php?taxonomy_name=the-taxonomy-name but I can’t confirm this works 100%.
Let me check if I can make a modification to return custom taxonomies on my test server 🙂
February 12, 2014 at 1:43 pm #968Ernest Marcinko
KeymasterOk, I need more information on this.
Let’s say you have a custom taxonomy called product-categories, which has the following terms: “Clothes”, “Food”, “Vegetables” …
Do you need the “product-categories” as the result, or the terms “Clothes”, “Food” … ?
February 12, 2014 at 2:13 pm #969Ernest Marcinko
KeymasterGood news. If you want to show the taxonomy terms in the result I have a working solution. You will need to open up the plugins/ajax-search-pro/search.php file and go to line 141, where you should see this:
$params = array('data'=>$search['data'], 'options'=>$search['options']);After this line, instert the following code:
/* Extra for searching custom taxonomies */ function _getAllTaxonomies() { $args = array( 'public' => true, '_builtin' => false ); $output = 'names'; // or objects $operator = 'and'; // 'and' or 'or' $taxonomies = get_taxonomies( $args, $output, $operator ); return $taxonomies; } function _getLikeTerms($name) { $taxonomies = _getAllTaxonomies(); $terms = array(); foreach ($taxonomies as $taxonomy) { $terms[$taxonomy] = get_terms($taxonomy, array( 'orderby' => 'name', 'name__like' => $name )); } return $terms; } $_like_terms = _getLikeTerms($s); $_termres = array(); foreach ($_like_terms as $taxonomy=>$terms) { foreach ($terms as $term) { //var_dump($term); $_termo = new stdClass(); $_termo->id = $term->term_id; $_termo->content = ""; $_termo->title = $term->name; $_termo->date = ""; $_termo->author = ""; $_termo->image = ""; $_termo->link = get_term_link( $term, $term->taxonomy ); $_termres[] = $_termo; } } $allpageposts = array_merge($allpageposts, $_termres); /* END Extra for searching custom taxonomies */And that’s it. Not sure how efficient this is, but this should work 🙂
February 12, 2014 at 2:32 pm #970webmarketingmaster
ParticipantThanks.. we will give it a try and let you know
February 12, 2014 at 2:38 pm #971webmarketingmaster
ParticipantOur custom taxonomies structure is http://DOMAIN.com/stores/taxonomy-name
The stores is constant and the stores/taxonomyname
I have my developer implimenting it right now.
February 12, 2014 at 2:56 pm #972webmarketingmaster
ParticipantWe are still stuck after adding the code you provided. How do we STOP showing any custom post type or pages and ONLY show the CUSTOM CATEGORIES we want to show? Are their settings on the backend we need to tweak?
February 12, 2014 at 3:08 pm #973Ernest Marcinko
KeymasterYou can turn off the search in posts, search in pages options on the backend, on the general options tab. But if you dont need those options it’s faster to add the following lines after the code I provided earlier:
print_r(json_encode($_termres)); die();This will make the search ignore everything after printing the category results – will make it somewhat faster.
You probably want to get rid of the settings box as well, it’s not needed for this kind of search. The best was to do this is by turning off everything on the “FRONTEND SEARCH SETTINGS” panel and after saving the options, the settings box will disappear from the frontend. -
This reply was modified 12 years, 3 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.