Skip to content

Instantly share code, notes, and snippets.

@jchristopher

jchristopher/functions.php Secret

Last active Sep 8, 2016
Embed
What would you like to do?
<?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
You can’t perform that action at this time.