Heads up!
This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
This hook can be used to change an “and” search to an “and/or” search. The hook actually works for both the quick search and advanced search settings, but in general, it was created especially for advanced searches that contain more search parameters.
Usage
add_filter( 'wpbdp_listing_search_parse_request', 'search_request', 10, 2 );
Parameters
- $search (array)
- $request (array)
Examples
Add ZIP search
This example will add a ZIP search to Quick Search Bar.
function search_request( $search, $request ) { $field_id = intval( wpbdp_get_option( 'zipcode-field', 0 ) ); // No quick search or integration not enabled. Nothing to do. if ( ! isset( $request['zipcodesearch'] ) || ! $field_id || ! wpbdp_get_option( 'zipcode-main-box-integration' ) ) { return $search; } // Remove this field from search terms. $search = WPBDP__Listing_Search::tree_remove_field( $search, $field_id ); // Add ZIP search. if ( ! empty( $request['zipcodesearch']['zip'] ) ) { $search[] = array( $field_id, $request['zipcodesearch'] ); } return $search; }
Replace the variable $field_id with the id of the field you need to add
Search “or” instead of “and”
This example will allow you to do a listing search “or” instead of “and”
function search_request( $search, $request ) { $search[0] = 'or'; return $search; }
This mainly applies when searching through these fields:
- Listing Title
- Short Description
- Description