Created
May 13, 2020 16:29
-
-
Save cparkinson/26113a68750fc937c245eeaf0d44465d to your computer and use it in GitHub Desktop.
FacetWP - index all posts demo
This file contains hidden or 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
/** | |
* 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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not actually useful, just for helping me figure out how to use the facetwp_indexer_row_data filter