Hello,
I am currently using WP Gridbuilder to filter my data stored in Meta Box Custom Fields (Woocommerce products).
One of the fields contains a string with many different type names, each separated by a comma.
Example:
Mercedes-Benz A220, BMW X6, VW Nutzfahrzeuge
I now need to filter all products by the individual vehicle models. For this I need the Meta Box Custom Field content as a nested array. Unfortunately, I don't seem to be doing this correctly. Where do I have the error and how should it read correctly?
add_filter(
'wp_grid_builder/indexer/index_object',
function( $rows, $object_id, $facet ) {
if ( 9 !== $facet['id'] ) {
return $rows;
}
$value = get_post_meta( $object_id, 'wccf_maschinenkompatibilitaet', true );
if ( empty( $value ) ) {
return $rows;
}
return [
array_map(
function( $value ) {
return [
'facet_value' => $value,
'facet_name' => $value,
];
},
explode( ',', $value )
),
];
},
10,
3
);
Thank you already