Note: You are viewing the documentation for Version 3View Version 4 Docs

Documentation

View the installation guide, browse the Knowledge Base, find out about SearchWP's many hooks, get support

Available since: 1.0

searchwp_where

View Parameters »

If you are an advanced developer and would like to directly manipulate the WHERE clause of the main search algorithm SQL you can use this filter.

Example: To customize the WHERE clause, add the following to your active theme’s functions.php:

<?php
function my_searchwp_where( $clause, $engine ) {
// manipulate $clause to your liking and return it
return $clause;
}
add_filter( 'searchwp_where', 'my_searchwp_where', 10, 2 );
view raw gistfile1.php hosted with ❤ by GitHub

Example: To limit results to a specific post_type based on a $_GET variable named post_type, add the following to your active theme’s functions.php:

<?php
function my_searchwp_limit_to_post_type( $clause, $engine ) {
global $wpdb;
if ( isset( $_GET['post_type'] ) ) {
$post_type = sanitize_text_field( $_GET['post_type'] );
if ( post_type_exists( $post_type ) ) {
$clause = $wpdb->prepare( "AND {$wpdb->prefix}posts.post_type = %s", $post_type );
}
}
return $clause;
}
add_filter( 'searchwp_where', 'my_searchwp_limit_to_post_type', 10, 2 );
view raw gistfile1.php hosted with ❤ by GitHub

Parameters

Parameter Type Description
$clause String

The original WHERE clause

$engine String

The search engine being used

Fix keyword search on your site. No coding required!

Now you can utilize all of the content that's gone unrecognized by native WordPress keyword search instantly with SearchWP

Get SearchWP