Created
March 14, 2019 18:30
-
-
Save mgibbs189/13c3c8ab80eb55f8cbf436273f959b26 to your computer and use it in GitHub Desktop.
Index taxonomy terms related to another taxonomy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment