This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Combine category and taxonomy

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Combine category and taxonomy

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #20704
    lorenzlorenz
    Participant

    I have a category named “betreuung”
    And I have a taxanomy named “betreuung”
    So, when I search for “betreuung” I get two (identical) lines for the results. See attached screen shot (first 2 lines):
    – Betreuung (119)
    – Betreuung (27)

    My customer, however, only wants so see one line;
    – Betreuung (146)

    I tried hard to solve this but did not succeed.

    Can you please help me with this?

    Thanks a lot,

    Regards
    Lorenz
    (Germany)

    #20712
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi!

    Well, this could get really difficult, as each taxonomy term is probably linking to a different location. I have put together small code snipptet, that will try to group the terms by name during the post process.
    Try adding this custom code to the functions.php in your theme/child theme directory (copy from line 3 only!). Before editing, please make sure to have a full site back-up just in case!

    add_filter('asp_results', 'asp_group_terms', 10, 1);
    function asp_group_terms($results) {
      $terms = array();
      $terms_occurence = array();
      $new_results = array();
      
      foreach($results as $k=>&$r) {
        if ( isset($r->taxonomy) ) {
          preg_match('/^(.*?)\((.*?)\)/', $r->title, $m);
          if ( isset($m[1], $m[2]) ) {
            $terms[$m[1]] = isset( $terms[$m[1]] ) ? $terms[$m[1]] + $m[2] : $m[2];
          }
        }
      }
      foreach($results as $k=>&$r) {
        if ( isset($r->taxonomy) ) {
          preg_match('/^(.*?)\((.*?)\)/', $r->title, $m);
          if ( isset($m[1], $m[2]) ) {
            // Already occured once, reset it
            if ( !isset($terms_occurence[$m[1]]) ) {
              $r->title = $m[1] . '(' . $terms[$m[1]] . ')';
              $new_results[] = $r;
              $terms_occurence[$m[1]] = true;  
            }       
          } else {
            $new_results[] = $r;
          }
        } else {
          $new_results[] = $r;
        }
      }
      
      return $new_results;
    }

    Please note, that this might not work in each and every case though.

    #20715
    lorenzlorenz
    Participant

    Thank you so much for your support. This is much more support than I have expected!
    I will let you know, how it works.

    Thanks,

    Lorenz
    (Germany)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.