Disable listing category from Add Listing page

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

1 Like