Guest User

Untitled

a guest
Jul 11th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Soderlind\Demo\SearchWP;
  4.  
  5. add_filter( 'searchwp_custom_field_keys', __NAMESPACE__ . '\\on_searchwp_custom_field_keys' );
  6. add_filter( 'searchwp_initial_engine_settings', __NAMESPACE__ . '\\on_searchwp_initial_engine_settings' );
  7. /**
  8. * Add custom fields to the search index
  9. *
  10. * @param array $keys
  11. * @return array
  12. */
  13. function on_searchwp_custom_field_keys( $keys ) {
  14. $keys[] = 'ingress';
  15. $keys[] = 'hogan_%'; // % = wildcard. I have multiple custom post types prefixed hogan_
  16. return $keys;
  17. }
  18. /**
  19. * On SearchWP activation, set the defaults for my custom post types.
  20. *
  21. * @param array $settings All of the default engine settings.
  22. * @return array
  23. */
  24. function on_searchwp_initial_engine_settings( $settings ) {
  25.  
  26. $post_types = array( 'post', 'page' );
  27. foreach ( $post_types as $post_type ) {
  28. $settings['default'][ $post_type ]['weights']['cf'][ uniqid( 'nettsteder' ) ] = array(
  29. 'metakey' => 'ingress',
  30. 'weight' => 40,
  31. );
  32. $settings['default'][ $post_type ]['weights']['cf'][ uniqid( 'nettsteder' ) ] = array(
  33. 'metakey' => 'hogan_%',
  34. 'weight' => 10,
  35. );
  36. }
  37.  
  38. return $settings;
  39. }
Add Comment
Please, Sign In to add comment