Support

Account

Home Forums General Issues Use a JS array to search through meta_query Reply To: Use a JS array to search through meta_query

  • No problem 🙂

    I’m not an SQL expert but I thiiiiink you can’t do a IN search with the checkbox field as the value in the DB will be a serialized array.

    I’m not sure how well this will play with your entire solution (and it’s not really performance-effective in the long run) but try if this works.

    
    function product_search() {
    	$products = $_POST['products'];
    	
    	$args = array(
    		'posts_per_page'	=> -1,
    		'post_type'				=> 'products',
    	);
    	
    	$meta_query = array();
    	foreach( $products as $product ){
    		$meta_query[] = array(
    			'key'		=> 'products',
    			'value'		=> $product,
    			'compare'	=> 'LIKE'
    		),
    		
    	}
    	
    	$args['meta_query'] = $meta_query;
    	
    }