Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active September 8, 2016 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/f04841cd045c9cb7a46fa267112a1150 to your computer and use it in GitHub Desktop.
Save jchristopher/f04841cd045c9cb7a46fa267112a1150 to your computer and use it in GitHub Desktop.
<?php
function my_searchwp_engine_customizations( $settings, $query ) {
// print_r( $settings ); // uncomment this line to see the settings structure
// print_r( $query ); // uncomment this line to see the query structure
// Check for Title-only search
if ( empty( $_REQUEST['searchwp_limit_to_title'] ) ) {
return $settings;
}
// Set all weights to zero except Title
foreach ( $settings as $post_type => $post_type_settings ) {
// If the post type isn't enabled, skip to the next
if ( empty( $post_type_settings['enabled'] ) ) {
continue;
}
// Set all weights to zero excerpt Titles
foreach ( $post_type_settings['weights'] as $content_type => $weight ) {
switch ( $content_type ) {
case 'title':
continue;
break;
case 'tax':
// Taxonomies have a different structure
foreach ( $weight as $taxonomy => $taxonomy_weight ) {
$settings[ $post_type ]['weights'][ $content_type ][ $taxonomy ] = 0;
}
break;
case 'cf':
// Custom Fields have a different structure
foreach ( $weight as $custom_field_uid => $custom_field_weight_pair ) {
$settings[ $post_type ]['weights'][ $content_type ][ $custom_field_uid ]['weight'] = 0;
}
break;
default:
$settings[ $post_type ]['weights'][ $content_type ] = 0;
}
}
}
return $settings;
}
add_filter( 'searchwp_engine_settings_default', 'my_searchwp_engine_customizations', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment