Guest User

Untitled

a guest
Feb 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <?php
  2. /**
  3. ** look up and index a value from a post relationship field
  4. ** set the datasource to the relationship field
  5. ** get the post id of that related post and use it to
  6. ** lookup its associated value
  7. ** for ACF you may want get_field() instead of get_post_meta()
  8. ** remember to do a full re-index after adding code
  9. ** check the wp_facetwp_index table if needed to see what values are being indexed
  10. **/
  11.  
  12. add_filter( 'facetwp_index_row', function( $params, $class ) {
  13. if ( 'my_facet' == $params['facet_name'] ) { // change my_facet to name of your facet
  14. $related_post_id = $params['facet_value']; // depnding on how your relationship field saves its data this might need to be changed or looked up from a different value
  15. $params['facet_display_value'] = get_post_meta( $related_post_id, 'some_custom_field', true ); // lookup custom field
  16. $params['facet_value'] = $params['facet_display_value'];
  17. }
  18. return $params;
  19. }, 10, 2 );
Add Comment
Please, Sign In to add comment