How to make tags required

Hi,

I had made the tags extension a required attribute when vendors submit a listing, but after changing it’s order - I’ve moved it near the top - it’s lost it’s required status and is now an optional attribute again.

This is the code snippet I’ve used to change the order:

add_filter(
	'hivepress/v1/forms/listing_update',
	function( $form ) {
		$form['fields']['tags']['_order']  = 75;

		return $form;
	}
);

And this is the one I used to make it required:

add_filter(
	'hivepress/v1/models/listing/attributes',
	function( $attributes ) {
		if ( isset( $attributes['tags'] ) ) {
			$attributes['tags']['edit_field'] = array_merge(
			$attributes['tags']['edit_field'],
			[
				'required' => true,
				'max_values' => 10,
			]
			);
		}
 
		return $attributes;
	},
	1000
);

OK, solved it by using this code snippet:

add_filter(
	'hivepress/v1/models/listing',
	function( $model ) {
		$model['fields']['tags']['required']  = true;
		
		return $model;
	}
);
1 Like