Zipko
January 12, 2023, 9:40pm
1
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.
andrii
January 13, 2023, 8:13pm
3
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.
Zipko
January 15, 2023, 2:14am
4
Thank you Andrii, it works.
system
Closed
February 14, 2023, 2:14am
5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.