FacetWP – index parent page

mgibbs189

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

/**
* 1. Add the following code to your (child) theme’s functions.php
* 2. Set your facet’s Data source to “Post Type”
* 3. Set your facet’s name (not label) to “post_parent”
* 4. Re-index
*/
add_filter( ‘facetwp_index_row’, function( $params ) {
if ( ‘post_parent’ == $params[‘facet_name’] ) {
$post_id = (int) $params[‘post_id’];
$parent_id = wp_get_post_parent_id( $post_id );
if ( $parent_id ) {
$parent_post = get_post( $parent_id );
$params[‘facet_value’] = $parent_post->post_name;
$params[‘facet_display_value’] = $parent_post->post_title;
}
else {
// empty the facet’s value
$params[‘facet_value’] = ”;
}
}
return $params;
});
{{/gist}}