• Hello!
    I have a question here.

    I’m trying to add a custom “global search” to the search widget. I create a new field named Global Search as free text. It appears on my FrontEnd searchbox but when I start searching for something, it shows no results, and the field doesn’t appear in the inside page.
    What should I do?

    https://wordpress.org/plugins/wp-property/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Maxim Peshkov

    (@maximpeshkov)

    Hello,

    the field doesn’t appear in the inside page.

    I guess there are different search widgets. You added global search field only for one of them.

    I create a new field named Global Search as free text.

    Be sure you have
    wpp_search[{YOUR_GLOBAL_SEARCH_NAME}]
    name for your custom field. So your custom field’s value will be appeared in
    $_REQUEST[ 'wpp_search' ]

    it shows no results

    get_properties() function is being used for searching properties. You should add the following ( it’s just example! ) filters:

    To add your custom attribute ( field ) to query:

    function my_wpp_get_properties_query( $query ) {
      if ( !empty( $_REQUEST['wpp_search']['YOUR_GLOBAL_SEARCH_NAME'] ) ) {
        $query['s'] = $_REQUEST['wpp_search']['YOUR_GLOBAL_SEARCH_NAME'];
      }
      return $query;
    }
    add_filter( 'wpp_get_properties_query', 'my_wpp_get_properties_query' );

    To allow custom search by specific query attribute:

    function my_wpp_get_properties_custom_case( $false, $meta_key ) {
      return $meta_key == 's' ? true : $false;
    }
    add_filter( 'wpp::get_properties::custom_case', 'my_wpp_get_properties_custom_case', 10, 2 );

    Do your custom search by your custom query attribute:

    function my_wpp_get_properties_custom_key( $matching_ids, $meta_key, $criteria ) {
    
      if ( $meta_key == 's' ) {
        $sub_query = new WP_Query(array(
          's' => $criteria,
          'post__in' => $matching_ids,
          'post_type' => 'property'
        ));
    
        $matching_ids = array();
    
        foreach( $sub_query->posts as $_post ) {
          $matching_ids[] = $_post->ID;
        }
      }
    
      return $matching_ids;
    }
    add_filter( 'wpp::get_properties::custom_key', 'my_wpp_get_properties_custom_key', 10, 3 );

    Regards.

    Thread Starter WPCISIS

    (@wpcisis)

    Wow thank you! I’ll try to customize the default search field based on your example.

    One more thing, I’m using the search widget of the Denali theme. Sorry, for some reason I forgot to be more specific in my first post.

    Plugin Contributor Maxim Peshkov

    (@maximpeshkov)

    Denali theme is using native WP-Property search functionality. So the solution should work for you.

    Please, be aware, you should use child theme of Denali to achieve your needs. It prevents the issues with theme upgrading in future.

    Regards.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Global Search’ is closed to new replies.