Hide specific categories on Add Listing

Hi, I would like my users to be able, when submitting a listing, to choose just some specific categories and not any of them. I don’t want to manually delete the categories I am not using cause I could use them in the future so I just want my users to be able to choose between some categories and hide the others from the Category selection dropdown in the Add listing form.

Ty!!

Found the solution:

add_filter(
	'hivepress/v1/models/listing/fields',
	function($fields, $model){
		$disabled_categories_ids = [1,2,3];
		
		if(isset($fields['categories']['options'])){
			foreach($disabled_categories_ids as $category_id){
				unset($fields['categories']['options'][$category_id]);
			}	
		}
		
		return $fields;
	},
	10000,
	2
);
2 Likes

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

In my setup the Categories are shown when I press Submit Listing
I dont want some Categories to be shown, neither their names|pictures, nor in the Category dropdown.
I saw a post here with some code. It didnt work for me.

Anyone who managed to do this, kindly help.
My Premium Support has expired so I am not requesting for help from the Support Team.
Thank you.

Hi,

Please make sure you added the PHP snippet using this documentation: How to add custom code snippets - HivePress Help Center. Also, please note that you need to add the category ID, which you can find in Listings > Categories by clicking Edit Category.

I hope it helps

i did it this way. did not work for me. can you confirm if the above code is working for you @andrii
thanks

Hi,

Yes, this snippet works correctly.

thanks @andrii
the snippet works (cannot list specific categories) but it does hide the pictures and options of the categories.
is there a way to also hide them ?

Hi,

Yes, it is possible, but it will require further customization.