• Resolved erictansh

    (@erictansh)


    I am using parent-child categories.

    If you see the linked page, I have the slug hierarchy set up like this

    parent-cat (0 review)
    – subcat-1 (8 reviews)
    – subcat-2 (0 review)
    – subcat-3 (1 review)
    – subcat-4 (0 review)

    [site_reviews_summary assigned_terms="subcat-1,subcat-3"] returns 8 reviews
    [site_reviews_summary assigned_terms="subcat-3,subcat-1"] returns 1 review
    [site_reviews_summary assigned_terms="parent-cat,subcat-1,subcat-3"] returns 0 review

    It seems like it is only reading the first term in the assigned_terms filter.

    • This topic was modified 3 years, 7 months ago by erictansh.
    • This topic was modified 3 years, 7 months ago by erictansh.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    Fixed in v5.13.2

    Thread Starter erictansh

    (@erictansh)

    Thanks for the quick fix!

    Just tested it and is working!

    Just one suggestion – any possibility of using the CPT’s taxonomy to filter the reviews instead of using site-review-category.

    Currently I have to write a hook to sync up the CPT’s terms and Site Reviews’ terms. This workaround will only works if the both categories’ slug matched exactly.

    It would be great if we can use the CPT’s taxonomy so to save the trouble having to match and sync both categories.

    add_filter('site-reviews/create/review-values', function ($values) {
      
      
      // Find the treatment categories of the posted review
    
      $terms = get_the_terms( $values['post_id'], 'treatment_cat' );
    
      $slugs = wp_list_pluck($terms, 'slug');
    
      // Match the treatment categories to that of the review categories using the slug
      foreach ($slugs as $slug) {
        $term = get_term_by( 'slug', $slug , 'site-review-category' );
        $assigned_terms[] = $term->term_id;
      }
      
      // Assign the terms to the review
      $values['assigned_terms'] = $assigned_terms;
    
      return $values;
    });
    Plugin Author Gemini Labs

    (@geminilabs)

    You can do this instead to automatically create the Site Reviews category if it doesn’t exist.

    add_filter('site-reviews/create/review-values', function ($values) {
        $assigned_terms = [];
        $terms = get_the_terms(glsr_get($values, 'post_id'), 'treatment_cat');
        foreach ($terms as $term) {
            if (!term_exists($term->slug, glsr()->taxonomy)) {
                wp_insert_term($term->name, glsr()->taxonomy, ['slug' => $term->slug]);
            }
            $assigned_terms[] = $term->slug;
        }
        if (!empty($assigned_terms)) {
            $values['assigned_terms'] = $assigned_terms;
        }
        return $values;
    });
    Thread Starter erictansh

    (@erictansh)

    Great

    Does $values[‘assigned_terms’] accept slugs? I tried yesterday and didn’t work.

    That’s why I need to convert to $term->id instead.

    Plugin Author Gemini Labs

    (@geminilabs)

    It should, but only if the slug exists as a Site Reviews category.

    Thread Starter erictansh

    (@erictansh)

    Tried but still didn’t work

    Note: there are more than 1 slug.

    add_filter('site-reviews/create/review-values', function ($values) {
      
      // Find the treatment categories of the posted review
    
      $terms = get_the_terms( $values['post_id'], 'treatment_cat' );
    
      $assigned_terms = wp_list_pluck($terms, 'slug');
      
      // Assign the terms to the review
      $values['assigned_terms'] = $assigned_terms;
    
      return $values;
    });
    Plugin Author Gemini Labs

    (@geminilabs)

    You actually can’t return slugs because at this point Site Reviews has already transformed any submitted category slugs to Term IDs.

    You will need to set an array of term IDs, not slugs.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘assigned_terms with multiple slugs is not working’ is closed to new replies.