Disable listing category from Add Listing page

Hi,
On our listing page, I don’t want to use categories. I’ve seen other questions on how to disable some categories, but not all of them.

Can I use a snip with PHP to make it not a required field?
If categories are mandatory, how can I make my single listing category selected by default, so I can hide it with CSS?

Thanks!
Sarah

Hi,

Please try this PHP snippet:

// Remove Category field from listing submit form
add_filter(
	'hivepress/v1/forms/listing_submit',
	function( $form ) {
		unset($form['fields']['categories']);	

		return $form;
	},
	1000
);

Also, please use this PHP snippet to set the default value for the listing category field. Then, the previous snippet to hide the category field should work correctly without showing an error:

add_action(
	'hivepress/v1/models/listing/create', 
	function($listing_id, $listing) {
		$listing->set_categories(category_id_here)->save_categories();
	}, 
	1000, 
	2
);

You must make additional customizations if you want the category selected by default.
If customizations are required for your site, please try customizing it using the collection of code snippets https://gist.github.com/search?q=user%3Ahivepress and other developer resources, or consider hiring someone for custom work Fiverr - Freelance Services Marketplace

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