• Resolved marcu5p

    (@marcu5p)


    Hi

    I have indexed a custom taxonomy:

    "taxonomies_hierarchical": {
        "global_tag": {
          "lvl0": [
            "Years and Months",
            "Employees",
            "Press and Media",
            "Resource Types",
            "Solutions",
            "Expertise",
            "Solutions by Name"
          ],
          "lvl1": [
            "Years and Months > 2022",
            "Employees > Harry Bunce",
            "Press and Media > Execution",
            "Resource Types > News",
            "Solutions > Reference",
            "Expertise > Regulataions",
            "Solutions by Name > Acme AI"
          ],
          "lvl2": [
            "Years and Months > 2022 > 07 - July 2022"
          ]
        }
      },

    Is it possible to use a filter (in a similar way to indexing custom fields) to index parts of this taxonomy separately?

    For example, create a new object array with only child terms of ‘Resource Types. As I have over 100 terms I would like to split the taxonomy across multiple facets.

    Thank you, any help appreciated.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    If I’m following, you’re wanting level 1 to be just “2022” and then level 2 to be just “07 – July 2022” ?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    That looks like part of a post object and it’s associated hierarchical taxonomy terms. I believe you can intercept and potentially adjust each item with the algolia_searchable_post_shared_attributes or algolia_searchable_post_MYPOSTTYPESLUG_shared_attributes filters and change things around, but I don’t have any immediate links or tutorials to change up how I assume you’re wanting this spot to look.

    Thread Starter marcu5p

    (@marcu5p)

    Hi Michael

    Thanks for the quick response.

    Yes, and then be able to create another object where it just shows children of Employees
    so level 1 is just “Harry Bunce”.

    Thanks
    Marcus

    Thread Starter marcu5p

    (@marcu5p)

    Ok, thanks for the pointer, I’ll investigate further.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hopefully you can get a solution that fits your need with this, though I can’t guarantee. Also this property is all part of the post object still, so I’m not sure exactly how much you’re going to get for potentially completely separate indexes.

    Worth tinkering with though.

    Thread Starter marcu5p

    (@marcu5p)

    Thanks for the steer really appreciate it. The below seems to do exactly what I wanted, but I need to do more testing to check.

    function ss_algolia_resource_attributes( array $attributes, WP_Post $post ) {
    
    $taxonomy = 'global_tag'; //Taxonomy Name
    $terms = get_the_terms( $post->ID, $taxonomy );
    
    $resource_type_children = '';
    
    foreach ( $terms as $term ) :
    if( $term->parent == 62 ) { //Parent Term ID
    $resource_type_children .= $term->name;
    } 
    endforeach;
    
    $attributes['resource_type'] = $resource_type_children;
    
    	return $attributes;
    }
    add_filter( 'algolia_post_shared_attributes', 'ss_algolia_resource_attributes', 10, 2 );
    add_filter( 'algolia_searchable_post_shared_attributes', 'ss_algolia_resource_attributes', 10, 2 );
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Sounds good.

    Thread Starter marcu5p

    (@marcu5p)

    Thank you.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Format a custom taxomony’ is closed to new replies.