Remove category from add listing form

How do i remove the category requirement for listings
I have no categories on my website but even still it is required to pick a category this really should be fixed for a future update

i tried to use this

But it still require there to be a category

Hi,

Please try 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
);

hello this is not work: pls help

add_filter(
	'hivepress/v1/forms/listing_submit',
	function( $form ) {
		$form['fields']['categories']['required']     = false;
		unset($form['fields']['categories']);
		return $form;
	},
	1000
);

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

Hi,

You did not need to change the first PHP snippet, please use these PHP snippets:

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

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

hello, error “required field” still same

Hi,

Please send us a screenshot of where you specify PHP snippets and which ones, so that we can check it in more detail, as everything is working correctly on our side.

Hi,

I see. Please use these PHP snippets:

add_filter(
	'hivepress/v1/forms/listing_submit',
	function( $form ) {
		unset($form['fields']['categories']);	

		return $form;
	},
	1000
);
add_filter(
	'hivepress/v1/models/listing',
	function( $args ) {
		$args['fields']['categories']['required'] = false;
		
		return $args;
	},
	1000
);

OK, its work … so this bellow part snippet is not necessary now? ( I don’t need to save in a category, but this part doesn’t work anyway) My plan is: Users post an listing without a category and I will then manually add listing to the category via the administration. Could this cause any problems in the future?

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

Hi,

Yes, you can delete this PHP snippet. No, there shouldn’t be any issues in the future.

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