Skip to content

Instantly share code, notes, and snippets.

@jchristopher
jchristopher / gist:81d8d0f1adc5802d7ba6
Created July 10, 2014 15:52
Prevent SearchWP from indexing certain meta key values using searchwp_excluded_custom_fields
<?php
function my_searchwp_excluded_custom_fields( $excluded ) {
// out of the box SearchWP ignores it's own meta fields so it's important to not overwrite $excluded
// ignore my_custom_field
$excluded[] = 'my_custom_field';
return $excluded;
}
@jchristopher
jchristopher / gist:e6b106a058e1c0d87978
Created July 10, 2014 15:54
Prevent SearchWP from indexing certain meta key values using searchwp_omit_meta_key
<?php
function my_searchwp_omit_meta_key( $omit, $custom_field, $post ) {
// ignore my_custom_field
if ( 'my_custom_field' === $custom_field ) {
$omit = true;
}
return $omit;
@jchristopher
jchristopher / gist:295b0f366c9ffec31782
Created July 10, 2014 15:55
Prevent SearchWP from indexing certain meta key values using searchwp_omit_meta_key_{$my_key}
<?php
// ignore my_custom_field
add_filter( 'searchwp_omit_meta_key_my_custom_field', '__return_true' );
<?php
// prevent 'wide' from being ignored by SearchWP
function my_searchwp_common_words( $terms ) {
if ( $key = array_search( 'wide', $terms ) ) {
unset( $terms[ $key ] );
}
return $terms;
}
<?php
function my_searchwp_index_chunk_size() {
// index 5 posts at a time instead of the default 10
return 5;
}
add_filter( 'searchwp_index_chunk_size', 'my_searchwp_index_chunk_size' );
<?php
/**
* USE CASE: I'm building a client site that has 3 main 'sections'
* - Portfolio
* - About
* - Solutions
*
* Each one of these 'sections' has a Page at the top level, which defines the URI segment
* - example.com/portfolio/
@jchristopher
jchristopher / gist:af00861c2b64b0181e8e
Created July 18, 2014 18:12
Tell SearchWP to enable SQL_BIG_SELECTS
<?php
add_filter( 'searchwp_big_selects', '__return_true' );
@jchristopher
jchristopher / gist:b26dd768fa2d37af61ff
Created July 18, 2014 19:00
Integrate SearchWP (and Fuzzy Matches et al.) With WP-Views Parametric Search
<?php
/**
* Tell WP Views Parametric Search to restrict it's results pool
* to what SearchWP finds, based on our custom setup
*/
global $doing_searchwp_search;
$doing_searchwp_search = false;
<nav>
<ul>
<li class="nav-about<?php if ( is_page( 83 ) ) : ?> current<?php endif; ?>">
<a href="<?php echo get_permalink( 83 ); ?>">About</a>
</li>
</ul>
</nav>
<nav>
<ul>
<li class="<?php if( TemplateMap()->maybe_in_section( 'template-about.php' ) ) : ?> current<?php endif; ?>">
<?php $about_page_id = TemplateMap()->get_id_from_template( 'template-about.php' ); ?>
<a href="<?php echo get_permalink( $about_page_id ); ?>">About</a>
</li>
</ul>
</nav>