Split custom field value into nested array

Support Meta Box AIO Split custom field value into nested array

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #40251
    BenBen
    Participant

    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

    #40273
    PeterPeter
    Moderator

    Hello,

    In case of using WPGrid Builder, please reach out to them if you have any issues with installation, configuration, compatibility, or usage.
    Refer to our support policy https://metabox.io/support/topic/support-policy/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.