Search block filter

  • Author
    Posts
  • Isaab

    Hello Ihor I wanted to inquire on search filter block add up. If it’s not up I was requesting for the css code please.

    ihordeveloper

    Thanks for your suggestion, if you mean a block for displaying the search filters I’ll consider adding it. Currently, you can use the search form block, it redirects users to the listing search page with filters.

    Isaab

    And how can I add a filter of an attribute instead of using the search for keywords

    ihordeveloper

    Adding attributes to the search form will be possible in the next version. Some extensions already add fields to the search form (like Geolocation), but it’s not possible for custom attributes yet, you can add them to the filters form instead.

    Isaab

    Hello Ihor hope you well. When will the next version for the search form filter option be available???

    ihordeveloper

    I plan to release it tomorrow, but this option will not be implemented in the next version (requires more testing, and styling for each attribute since the search form is horizontal). Please let me know what attributes you want to add to the search form and I’ll provide a temporary code snippet for this.

    issab

    I want to put a body type attribute and services

    ihordeveloper

    Here’s a sample snippet that adds a custom attribute “Services” to the main search form:

    add_filter(
    	'hivepress/v1/models/listing/attributes',
    	function( $attributes ) {
    		if ( isset( $attributes['services'] ) ) {
    			$attributes['services']['searchable'] = true;
    		}
    
    		return $attributes;
    	}
    );

    You can replace “services” with any other attribute slug (slug is an attribute name in lowercase and with underscores, e.g. for “Body Type” it’s “body_type”). Please note that attributes may not fit well in the main search form, only horizontal fields will fit there (like text, number or select fields).

    issab

    I have put the snippet and it has worked. The only problem is the search results are not accurate till you use the filter button???

    workin

    Hi Ihor. Is it possible to do the same but for categories instead of attributes?

    ihordeveloper

    @issab I tested this locally with the “Pets” attribute from the demo content (it’s a selectable attribute https://demo.hivepress.io/listings/ and it seems to work.


    @workin
    This one should do it:

    add_filter(
    	'hivepress/v1/forms/listing_search',
    	function( $form ) {
    		$form['fields']['_category'] = [
    			'label'       => 'Category',
    			'type'        => 'select',
    			'options'     => 'terms',
    			'option_args' => [ 'taxonomy' => 'hp_listing_category' ],
    			'_order'      => 100,
    		];
    
    		return $form;
    	}
    );

    Please note that it will not preserve the hierarchy.

    Isaab

    Yes it appeared that way but when searching it just gives me the whole results features

    ihordeveloper

    You can send a link to this page to support@hivepress.io and I’ll check it.

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

You must be logged in to reply to this topic.

Subscribe

Sign In

Don't have an account? Register

Forgot password?

Register

Already have an account? Sign In

Forgot password?

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.