Last active
February 11, 2020 16:41
-
-
Save mgibbs189/81baf175d8804b08f7d25db3bbfcda6f to your computer and use it in GitHub Desktop.
FacetWP - index variation attribute with "Any" select
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 | |
add_filter( 'facetwp_indexer_row_data', function( $rows, $params ) { | |
$defaults = $params['defaults']; | |
$post_id = (int) $defaults['post_id']; | |
if ( 0 === strpos( $defaults['facet_source'], 'cf/attribute_pa_' ) ) { | |
if ( 'product_variation' == get_post_type( $post_id ) ) { | |
$parent_id = wp_get_post_parent_id( $post_id ); | |
$tax = str_replace( 'cf/attribute_', '', $defaults['facet_source'] ); | |
$terms = get_the_terms( $parent_id, $tax ); | |
if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) { | |
foreach ( $terms as $term ) { | |
$temp = $defaults; | |
$temp['term_id'] = $term->term_id; | |
$temp['facet_value'] = $term->slug; | |
$temp['facet_display_value'] = $term->name; | |
$temp['variation_id'] = $post_id; | |
$temp['post_id'] = $parent_id; | |
$rows[] = $temp; | |
} | |
} | |
} | |
} | |
return $rows; | |
}, 999, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 8 : get_post_tyoe should be get_post_type