Search Query Filter

Viewing 2 posts - 1 through 2 (of 2 total)

These forums are closed to new replies / tickets. Please open a support ticket from our new Support page.

  • Author
    Posts
  • #21060
    xMikey
    Participant

    Can’t seem to get the search widget to filter properly with a custom field.

    We’ve added an “Agent” field following this documentation: https://easypropertylistings.com.au/docs/how-to-add-your-custom-fields-to-the-search-widget/

    The “Agent” drop-down field shows up appropriately on the front-end. When you select an agent and hit search it adds the parameter &agent={agent_id_here} to the URL. The results however are not filtering by agent. Not quite how to get the query part working. Here is a sample code:

    function my_epl_custom_search_widget_fields_frontend_callback( $array ) {
        $array[] = array(
            'key'       =>   'agent_search',
            'meta_key'  =>   'agent',
            'label'     =>   __('Agent', 'epl'),
            'type'      =>   'select',
            'option_filter' =>   'custom_search_filter_1',
            'options'   =>   get_authors($author_array),
            'query'     =>   array(
                            'query'     =>   get_the_author(),
                            'key'       =>   'custom_property_meta_key_1',
                            'type'      =>   'numeric',
                            'compare'   =>   '='
                        ),
            'class'     =>   'epl-search-row epl-search-building-area',
        );
        return $array;
    }
    add_filter( 'epl_search_widget_fields_frontend' , 'my_epl_custom_search_widget_fields_frontend_callback' );

    Any help would be greatly appreciated! Thank you!

    #21099
    Merv Barrett
    Keymaster

    The type ‘numeric’ should be ‘select’ and you will need to pass the options that the user can select from.

    Also your ‘options’ setting is get_authors($author_array) but $author_array is undefined in your function.

    meta_key is a different variable than your custom_property_meta_key_1.

    This is the search functions file on github with more examples of how the search function works

    Here is the search array for house category which is similar to an agent search

    array(
    	'key'			=>	'search_house_category',
    	'meta_key'		=>	'property_category',
    	'label'			=>	__('House Category','epl'),
    	'option_filter'		=>	'category',
    	'options'		=>	epl_get_meta_values( 'property_category', $post_type),
    	'type'			=>	'select',
    	'query'			=>	array('query'	=>	'meta'),
    	'class'			=>	'epl-search-row-full',
    	'exclude'		=>	array('land','commercial','commercial_land','business'),
    ),

    We can help you further with a priority support request

These forums are closed to new replies / tickets. Please open a support ticket from our new Support page.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Basic Support’ is closed to new topics and replies.