How to set up max tags users can choose

Hi There,

I used this snippet to set maximum tags users can choose, but it is not working. I changed it from 3 to 20 and I am still getting “Tags” field contains too many values error message.
Is there any other snippet to set max tags or 10 tags is a maximum possible?

Thank you.

Hi,

Please try this PHP snippet:

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

add_filter( 
 'hivepress/v1/models/listing',
 function ($model){
  if(isset($model['fields']['tags'])){
   $model['fields']['tags']['max_values'] = 20;
  }
  
  return $model;
 },
 1000
);

add_filter( 
 'hivepress/v1/forms/listing_update/errors', 
 function ($errors, $form){
  if(count((array)$form->get_value('tags')) < 1){
   $errors[] = 'Please set at least one tag';
  }
  
  return $errors;
 },
 1000,
 2
);

Please note that you may require additional customizations in the future.

Thank you Andrii, it works.

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