Last active
August 24, 2020 17:45
-
-
Save djrmom/6218a4646e8d1d2a453025a90110a2a0 to your computer and use it in GitHub Desktop.
facetwp index relationship
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
| <?php | |
| /** make the datasource something you know will always have a value for every post - like post title - it | |
| ** is only a placeholder and won't be indexed | |
| **/ | |
| add_filter( 'facetwp_index_row', function( $params, $class ) { | |
| if ( 'search_new' == $params['facet_name'] ) { // change my_facet to name of your facet | |
| $project_id = $params['post_id']; | |
| /** some code here to make an array of post ids of | |
| people posts that are associated with the project **/ | |
| // loop of array of people post ids you have created above | |
| foreach ( $people_posts as $people ) { | |
| // Update the values to be inserted into database. | |
| $people_title = get_the_title( $people ); | |
| $people_params = $params; | |
| $people_params['facet_value'] = $people_title; | |
| $people_params['facet_display_value'] = $people_title; | |
| // Insert each value to the database. | |
| $class->insert( $people_params ); | |
| } | |
| $params['facet_value'] = ''; // we won't index the original value | |
| } | |
| return $params; | |
| }, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment