How to create a Wordpress meta query when the meta value is a JSON string value

I’m wrestling with how to build this meta query. Any ideas on how to do it?

I’m trying to implement a Post module query filter and I’m hoping you can help me out how to do it in this situation. I have a meta key/value that has a JSON string in it. I need to extract and compare one of the JSON key values for the meta query.

Meta key: ‘_mbr_woocommerce_product_data’
Value (JSON): string(1657) “{“assign_tags”:[“222”],“remove_tags_refunded”:[“222”],“sku_tag_name”:”“,“product_tag_names”:”" etc…

JSON key: ‘assign_tags’
Value: 222

So is there a way to create the meta query to extract out the nested JSON key value? Something like the below?

The problem area would be in this line where I’m trying to get the nested JSON key:
‘key’ => ‘_mbr_woocommerce_product_data’ → assign_tags,

/*Advanced Query Parameters filtering for UABB Posts module */
function wss_uabb_blog_posts_query_args( $args, $settings ) {
  // Give an HTML id and check it before modifying arguments so that it will not be applied to all blog post modules on the site.
  if ( !$settings->id == 'events-list' ) {
                 $meta_query = array(
                                'relation' => 'OR',
                                array(
                                               'key'     => '_mbr_woocommerce_product_data' -> assign_tags,
                                               'value'   => '222,345,987',
                                               'compare' => 'IN',
                                               'type'    => 'CHAR',
                                ),
                 );
  
                 $args['meta_query'] = $meta_query;
                 
  }
  return $args;
}
add_filter( 'uabb_blog_posts_query_args', 'wss_uabb_blog_posts_query_args', 40, 2 );

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.