Filter against custom taxonomy

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Filter against custom taxonomy

This topic contains 15 replies, has 3 voices, and was last updated by webmarketingmaster webmarketingmaster 8 years, 6 months ago.

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #781
    iltdev
    iltdev
    Participant

    I 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?

    #782
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #784
    iltdev
    iltdev
    Participant

    Hi,

    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.

    #949
    webmarketingmaster
    webmarketingmaster
    Participant

    Has 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.

    #951
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Actually 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 πŸ™‚

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #959
    webmarketingmaster
    webmarketingmaster
    Participant

    Great News!! Im going to buy your plugin right now!

    Thanks for the prompt response.

    #964
    webmarketingmaster
    webmarketingmaster
    Participant

    Im running into a problem. I NEED the taxonomy to SHOW UP as the SEARCH RESULT and be clickable. How do I accomplish this?

    #965
    webmarketingmaster
    webmarketingmaster
    Participant

    One 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

    #967
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    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 πŸ™‚

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #968
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Ok, 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” … ?

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #969
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Good 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 πŸ™‚

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #970
    webmarketingmaster
    webmarketingmaster
    Participant

    Thanks.. we will give it a try and let you know

    #971
    webmarketingmaster
    webmarketingmaster
    Participant

    Our 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.

    #972
    webmarketingmaster
    webmarketingmaster
    Participant

    We 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?

    #973
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    You 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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic.