Created
July 11, 2018 23:25
-
-
Save soderlind/1426b552431e399e980d322175bc8c65 to your computer and use it in GitHub Desktop.
On SearchWP activation, set the defaults for my custom post types.
This file contains 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 | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment