SearchWP

This Documentation is for SearchWP Version 3

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

[wpforms id="3080"]