Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Soderlind\Demo\SearchWP;
- add_filter( 'searchwp_custom_field_keys', __NAMESPACE__ . '\\on_searchwp_custom_field_keys' );
- add_filter( 'searchwp_initial_engine_settings', __NAMESPACE__ . '\\on_searchwp_initial_engine_settings' );
- /**
- * Add custom fields to the search index
- *
- * @param array $keys
- * @return array
- */
- function on_searchwp_custom_field_keys( $keys ) {
- $keys[] = 'ingress';
- $keys[] = 'hogan_%'; // % = wildcard. I have multiple custom post types prefixed hogan_
- return $keys;
- }
- /**
- * On SearchWP activation, set the defaults for my custom post types.
- *
- * @param array $settings All of the default engine settings.
- * @return array
- */
- function on_searchwp_initial_engine_settings( $settings ) {
- $post_types = array( 'post', 'page' );
- foreach ( $post_types as $post_type ) {
- $settings['default'][ $post_type ]['weights']['cf'][ uniqid( 'nettsteder' ) ] = array(
- 'metakey' => 'ingress',
- 'weight' => 40,
- );
- $settings['default'][ $post_type ]['weights']['cf'][ uniqid( 'nettsteder' ) ] = array(
- 'metakey' => 'hogan_%',
- 'weight' => 10,
- );
- }
- return $settings;
- }
Add Comment
Please, Sign In to add comment