Docs & Support

Learn about all Business Directory’s features and get support from our amazing customer success team.

CustomizationsHooks – For Developers
wpbdp_listing_search_parse_request

wpbdp_listing_search_parse_request

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 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

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
Was this article helpful? *

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

In this article

    We have a small, but amazing team of dedicated people who are committed to helping you achieve your goals and project requirements.


    Copyright © 2010-2025 S11 Directories, LLC.

    Join 20,000+ using Business Directory Plugin to build website directories fast. Get Started