Using Custom Term Meta Fields in Filters

  • Solved
  • Posted 1 month ago

Hi Voxel Support Team,

We want our category filters to display the name stored in term meta (name_en and name_ar) instead of the default term name.

Here is what we have done so far:
1. Added name_en and name_ar fields in wp_termmeta for each term.
2. Registered dynamic data tags in Voxel for these fields.

add_filter(‘voxel/dynamic-data/groups/term/properties’, function($properties, $group) {
$properties[‘name_en’] = \Voxel\Dynamic_Data\Tag::String(‘English Name’)
->render(function() use ($group) {
return get_term_meta($group->term->get_id(), ‘name_en’, true);
});
$properties[‘name_ar’] = \Voxel\Dynamic_Data\Tag::String(‘Arabic Name’)
->render(function() use ($group) {
return get_term_meta($group->term->get_id(), ‘name_ar’, true);
});
return $properties;
}, 10, 2);
———-

3. Successfully used @post(category.name_en) and @post(category.name_ar) in cards, lists, and buttons.

Our goal:
We want the search filters (dropdowns) to display the term name based on the site language, using these meta fields, without adding extra fields in the UI.

Could you please advise how we can make the filter component use these custom meta fields for term names? If there is a hook or recommended approach to achieve this, we would appreciate your guidance.

Thank you!