Preselect Filter with Hook in WPSolr Search Page

  • 9 months, 3 weeks ago #34955

    Hi, Is there any filter/hook to preselect the filters, as there is option but no condition to add …
    Image image.png of Preselect Filter with Hook in WPSolr Search Page

    wpsolr
    Keymaster
    9 months, 3 weeks ago #34960

    There are no filters for that, but you can preselect filters with url parameters:
    – Select your filter(s) in the ui,and copy the url
    – use the url on a link, or a form action

    9 months, 3 weeks ago #34967

    Okay, actually my requirement was for a clean url, with filter selected..
    I found this code, but didnt see any hook to use it
    [class-wpsolr-option.php]

    public function get_facets_items_is_default() {
    return $this->get_option_value( true, __FUNCTION__, self::OPTION_FACET, self::OPTION_FACET_FACETS_ITEMS_IS_DEFAULT, [] );
    }
    wpsolr
    Keymaster
    9 months, 3 weeks ago #34969

    You can use WPSOLR_Events::WPSOLR_FILTER_BEFORE_GET_OPTION_VALUE, which is a low level filter to capture any WPSOLR options.

    private function get_option_value( $is_cached, $caller_function_name, $option_name, $option_key, $option_default = null ) {
    
    		if ( ! empty( $caller_function_name ) ) {
    			// Filter before retrieving an option value
    			$result = apply_filters( WPSOLR_Events::WPSOLR_FILTER_BEFORE_GET_OPTION_VALUE, null, [
    				'option_name'     => $caller_function_name,
    				'$option_key'     => $option_key,
    				'$option_default' => $option_default,
    			] );
    			if ( ! empty( $result ) ) {
    				return $result;
    			}
    		}
    ...
    }
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.