Index taxonomy terms related to another taxonomy

mgibbs189

{{gist file=”functions.php” lang=”php”}}
<?php

/**
* “Found object” is the post type
* The post type has a “Materials” taxonomy
* The “Materials” taxonomy is associated with a “Physical Properties” taxonomy
*
* For the facet’s name, use “physical_properties”
* For the facet’s Data source, select the “Materials” taxonomy
*/
add_filter( ‘facetwp_index_row’, function( $params, $class ) {
if ( ‘physical_properties’ == $params[‘facet_name’] ) {

// TODO – create this function to return all physical properties associated with this “materials” term ID
// It should return an array of term objects
$physical_properties = get_physical_property_terms( $params[‘term_id’] );

foreach ( $physical_properties as $prop ) {
$params[‘facet_value’] = $prop->slug;
$params[‘facet_display_value’] = $prop->name;
$params[‘term_id’] = $prop->term_id;
$class->insert( $params );
}

// Exit stage left
$params[‘facet_value’] = ”;
}
return $params;
}, 10, 2 );

{{/gist}}