Hide facet filter in frontend

  • 1 year, 7 months ago #30872

    Hi, How Can I hide a particular facet from facet widget, even after its added to Data tab 2.2 and also filter, Can you help me with this ?

    wpsolr
    Keymaster
    1 year, 7 months ago #30873

    You could be interested in this topic about hiding certain facet values

    1 year, 7 months ago #30881

    Actually, the solution provided in the link is a bit different, I checked those options, its showing list of each item in parent facet to hide, What I was looking for is to hide the entire parent facet, some particular ones, which needs to be there in data and filter but not render into html.

    wpsolr
    Keymaster
    1 year, 7 months ago #30882

    You should then remove the facet from the facets definition in screen 2.4

    1 year, 7 months ago #30883

    Any option, with filter enabled in 2.4. Any hook or condition to add in some file which can match that facet and hide in html, if we provide facet id ?

    wpsolr
    Keymaster
    1 year, 7 months ago #30884

    No, but you can use some css to hide the facet. Each facet has a unique id.

    1 year, 7 months ago #30886

    I have inspected the filters, and found there is a class being added to each facet like wpsolr_facet_xxxx_str . So any place where I can mention this class name, to stop it rendering, not preferably with css or jquery..

    wpsolr
    Keymaster
    1 year, 7 months ago #30887

    You can try:

    <?php
    
    use wpsolr\core\classes\WPSOLR_Events;
    
    add_filter( WPSOLR_Events::WPSOLR_FILTER_UPDATE_FACETS_DATA, 'hide_facets', 10, 1 );
    
    /**
     *
     * Hide facets.
     *
     * @param array $facets_data
     *
     * @return array
     */
    public function hide_facets( $facets_data ) {
    
    	/**
    	 * unset the facet from $facets_data['facets']
    	 */
    
    	return $facets_data;
    }
Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.