Hi guys!
So I have an AJAX request that is supposed to pick up data from a couple of checkboxes and then filter the search based on which ones are selected.
For my JS, I have this segment to get the checkboxes:
products = new Array();
$('input#products:checked').each(function() {
products.push($(this).val());
});
And in my functions.php, I have this:
function product_search() {
$products = $_POST['products'];
$args = array(
'posts_per_page' => -1,
'post_type' => 'products',
'meta_query' => array(
array(
'key' => 'products',
'value' => $products,
'compare' => 'IN'
),
)
);
// [...]
}
Now, if I change $products to something static, I get my results, but the array that’s being parsed from my JS doesn’t play well here. I’ve tried to used json_decode() on $products, without any good results.
If I console log the products var, I can get this if I have two checkboxes checked:
["Wooden", "Plastic"]
How can I make these guy come along?
Thanks in advance!