Disable category selection in listing creation

Hello,
We have created few categoeries, but we want to disable one category, so it wouldn’t be selectable at listing creation. Only administrator will be able to create this listing manually in wp-admin. Is it possible to hide one category from listing form?

Hi, I do not think you can hide the categories from showing in the listing edit or search…

However, with Paid Listings extension, if you assign a package to specific categories, then only these categories will be restricted and will require purchasing or selecting a package. In other words, the users will not be able to open the page.

1 Like

Please try this PHP snippet. Please change 1,2,3 on the categories id which you want to hide

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

Is this for listing submission form? Nothing seems to happen :confused:

When editing a listing front end

It is needed for listing submission form, when user creates a listing he can’t see specific category

Hey yea I tried the code snippet, and it worked for me. When the user is adding a listing, they can’t see the category.

Did you substitute the category ID numbers in the place of the 1,2,3 in the code above? Each category ID (located on top of the browser) in place of each of those numbers?

Please make sure that you have correctly put the snippet with the Code Snippets plugin or the similar one. Also please change 1,2,3 on the categories id which you want to hide

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