Listing Search Form Parent Category

Hello,

I am trying to customize a directory site with multiple categories and sub-categories and I can’t find a way to display a Listing Search Form with only a specific category and its child-categories, instead of root. Is there a way or is it even or feature request list for development?

I had used in the past similar products with hivepress and this functionality was something common. For example in a big city directory with multiple categories and subs, I could create a custom page for the most visited categories and the Search specifying only the category I would like to display ( Health and subs instead of Root)

Root
Health
** |->Doctors**
** |->Pharmacy**
->Beauty
->Clothing
|->Clothes
|->Shoes

1 Like

I have used some snippets and hide the category from Search and from Add Listings Form. Now i need to find a way to hide the category from Search Results block. Probably by modifiyng a snippet for (hivepress/v1/models/listing/search).

// Custom - Exclude category from Search
add_filter(
	'hivepress/v1/forms/listing_search',
	function($args){
		if(isset($args['fields']['_category'])){
			$args['fields']['_category']['option_args']['exclude'] = [229];
		}
		
		return $args;
	},
	1000
);

// Custom - Exclude category from Add Listing
add_filter(
	'hivepress/v1/models/listing/fields',
	function($fields, $model){
		$disabled_categories_ids = [229];
		
		if(isset($fields['categories']['options'])){
			foreach($disabled_categories_ids as $category_id){
				unset($fields['categories']['options'][$category_id]);
			}	
		}
		
		return $fields;
	},
	10000,
	2
);

Hi,

Please provide more details on what you need this function to do. Perhaps you mean to disable the ability to filter by category or show the form filter on other parts of the page with different category combos?

Let’s say that we have the following structure(i will put numbering so the categories and subs are easily identified):

A.Business Catalog Category
A1 >Cat 1
A1.1 >Cat 1-Sub1
A1.2 >Cat 1-Sub2
A2 >Beauty
A3> Clothing
A3.1 >Cat 3-Sub1
A3.1 >Cat 3-Sub2
A# >Cat N#
B. Other Catalog Category
B1 >Cat 1
B2 >Cat 2
B2.1 >Cat 2-Sub1
B2.2 >Cat 2-Sub2

At the Listing Search Form block, you can’t select the Category you desire as a Parent.
hivepress-listing-search-block

At the Listing Categories block, you can select the Category you desire as a Parent.

So if we want to show a Listing Search Form block on a page, for a specific Category (A.Business Catalog) the dropdown displays everything (B. Other Catalog).

On the contrary, if we want to show a Listing Categories block on a page, for a specific Category (A.Business Catalog), it displays the categories or listings of the Parent Category you specify.

The only way to hide a Category from the Listing Search Form block is to create a fake parent category (A.Business Catalog), move everything you want to be visible there and use the above snippet to hide the rest categories (moved under B. Other Catalog). But there is a problem with this approach. You have an extra layer on the dropdown (A.Business Catalog), that has all the categories to display as subCategories.

If at the Listing Search Form block, you could select the Category you desire as a Parent, you could create as many category-specific pages that display only the desired categories and subs.

So to summarise, I don’t want the “B. Other Catalog Category & subs” to be visible on the Listing Search Form block and the Listing Categories block. With the above snippets i succedded to hide it fron the Listings Search but it seem wrong to have the categories dysplayed as subs for no reasson.

Hi,

Unfortunately, there’s no such feature, it would require a custom implementation. We recommend using this hook hivepress/v1/forms/listing_search, with it, you can set the default category, and then hide the selection field itself using CSS.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.