Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
Created March 14, 2019 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgibbs189/13c3c8ab80eb55f8cbf436273f959b26 to your computer and use it in GitHub Desktop.
Save mgibbs189/13c3c8ab80eb55f8cbf436273f959b26 to your computer and use it in GitHub Desktop.
Index taxonomy terms related to another taxonomy
<?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