Skip to content

Instantly share code, notes, and snippets.

@cparkinson
Created May 13, 2020 16:29
Show Gist options
  • Save cparkinson/26113a68750fc937c245eeaf0d44465d to your computer and use it in GitHub Desktop.
Save cparkinson/26113a68750fc937c245eeaf0d44465d to your computer and use it in GitHub Desktop.
FacetWP - index all posts demo
/**
* Filter to customize FacetWP, should be pasted in FacetWP's "Custom Hooks" plugin
*
* Made as a demo so I could figure out how FacetWP index filter works.
* gives every post an entry in the "location_filter" facet
*
*/
add_filter( 'facetwp_indexer_row_data', function( $rows, $params ) {
if ( 'location_filter' == $params['facet']['name'] ) {
$new_row = $params['defaults'];
$post_id = (int) $new_row['post_id'];
$new_row['facet_value'] = $post_id; //id of the current existing post
$new_row['facet_display_value'] = get_the_title( $post_id ); //title of post
$rows[] = $new_row;
}
return $rows;
}, 10, 2 );
@cparkinson
Copy link
Author

Not actually useful, just for helping me figure out how to use the facetwp_indexer_row_data filter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment