Add multiple category selection support to the back-end form

Add this code snippet using the Code Snippets plugin or to the child theme’s functions.php file:

add_filter(
	'hivepress/v1/meta_boxes/listing_attributes',
	function( $meta_box ) {
		if ( isset( $meta_box['fields']['categories'] ) ) {
			$meta_box['fields']['categories']['multiple'] = true;
			unset( $meta_box['fields']['categories']['attributes']['data-multistep'] );
		}

		return $meta_box;
	},
	1000
);

Change line 187 in hivepress/includes/controllers/class-attributes.php file:

wp_set_post_terms( $post->ID, [ absint( $request->get_param( hp\prefix( 'categories' ) ) ) ], $taxonomy );

to:

wp_set_post_terms( $post->ID, array_map( 'absint', (array) $request->get_param( hp\prefix( 'categories' ) ) ), $taxonomy );

The file change will not be needed in future updates because we’ll make the same change in the next one. Please note that this may still cause issues because there are a few features in the code that rely on a single category selection.

Thank you! I made the changes, it seems to work, but the phone number is not reaching me (back end). I uploaded an apartment myself to check, and the number line comes up blank. I will greatly appreciate your help.

1 Like

Hi,

Please provide more details on what exactly you mean by “phone number is not reaching me” and we will try to help (for example, when you select a category when creating a listing, the number field does not appear or cannot be changed, etc.). If so, try selecting a category and refreshing the page.

Thanks for the feedback! When I click on the categories at the back end (picture attached), (to add, or change) the phone number immediately disappears (ie the information inside is deleted). I am currently copying it and keeping it aside, editing the categories - and then pasting it again. I would be very happy if you could fix this problem

Hi,

Thanks for the feedback, we will fix it in the next update. We plan to release an update this quarter.

1 Like

Can you help me complete this step? When I go to my snippets plugin, there are tabs for Functions (PHP), Content (HTML), Styles (CSS), and Scripts (JS). Where should I place this snippet?

Also the part where you say, change line 187 to …

I don’t see where you find this. I can’t find this. Where should I look?

Hi,

Regarding the snippet, please use this doc: How to add custom code snippets - HivePress Help Center

As for the code, please check this screenshot: Awesome Screenshot

​I hope this is helpful to you.