Hello HivePress team,
I’ve been working on adding the possibility for vendors to select up to 5 categories (most vendors/ professionals are able to do multiple things from different domains) when editing their profile. So I worked with AI, and after some time, I managed to achieve a partially satisfiable result through the following code:
// Add multiple category selection to the vendor profile edit form
add_filter(
'hivepress/v1/forms/vendor_update',
function( $form ) {
$categories = get_terms([
'taxonomy' => 'hp_vendor_category',
'hide_empty' => false,
]);
$options = [];
foreach ($categories as $cat) {
$options[$cat->term_id] = $cat->name;
}
$values = [];
$user_id = get_current_user_id();
$vendor_id = false;
if ($user_id) {
$vendor_query = new WP_Query([
'post_type' => 'hp_vendor',
'post_status' => 'publish',
'author' => $user_id,
'posts_per_page' => 1
]);
if ($vendor_query->have_posts()) {
$vendor_id = $vendor_query->posts[0]->ID;
}
wp_reset_postdata();
}
if ( $vendor_id ) {
$terms = wp_get_object_terms($vendor_id, 'hp_vendor_category');
if(count($terms) > 0) {
foreach($terms as $t) { $values[] = $t->term_id; }
}
}
$form['fields']['hp_vendor_category'] = [
'type' => 'select',
'label' => 'Select trades',
'options' => $options,
'value' => $values,
'multiple' => true,
'required' => true,
'max_values' => 5, // Just informative
'placeholder' => 'maximum 5 trades',
'description' => 'You can select up to 5 categories',
];
return $form;
}
);
add_action(
'hivepress/v1/models/vendor/update',
function($vendor_id, $vendor){
if( isset($_POST['hp_vendor_category']) ){
$cats = $_POST['hp_vendor_category'];
if(is_array($cats)) {
if(count($cats) > 5) {
$cats = array_slice($cats, 0, 5);
}
$cats = array_map('intval', $cats);
wp_set_object_terms(
$vendor_id,
$cats,
'hp_vendor_category',
false
);
} else {
wp_set_object_terms(
$vendor_id,
intval($cats),
'hp_vendor_category',
false
);
}
}
},
10,
2
);
The issues I face:
-
When registering a new vendor, the default/inherited category selector still only allows single selection, then our additional multi-select appears (users end up selecting the category twice).
-
After saving, if you revisit the settings, only one selected category is visible in our multi-select field, even though all categories are actually linked to the vendor in the backend.
-
In the WP admin/backend, editing vendor categories still shows a single-select field, so only one category can be managed visually—though the database can store multiple.
What I want to do
Instead of adding an additional multi-select field, I would like to target and convert the default “category” selector for vendors into a multiple-selection box (both front-end and backend), so the experience is seamless and only one field controls category assignment everywhere.
Is there a recommended, up-to-date way to achieve this?
If not, would you consider adding support for this use case in a future HivePress release (for example, by allowing the built-in vendor category field to accept multiple categories and show them properly when re-editing the profile)?
Thank you!