I need to push js variable into php variable. AJAX url is set via wp_localize_script but it returns ERROR 400 Bad Request. functions.php is looks like
wp_localize_script( 'script-js', 'compareids_ajax', array( 'ajax_url' => admin_url('admin-ajax.php')) );
custom.js
var compareIDs = $(".table td input:checkbox:checked").map(function(){
return $(this).val();
}).get(); // <----
$('.selected').text(compareIDs);
console.log(compareIDs);
$.ajax({
type: "POST",
url: compareids_ajax.ajax_url,
data: '{ compareIDs : compareIDs }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
},
error: function (errormessage) {
}
});
and my filter-page.php has
<?php
$compareIDs = array( $_POST['compareIDs'] );
$args02 = array( 'post_type' => 'custom',
'post__in' => $compareIDs );
$loop02 = new WP_Query( $args02 );
while ( $loop02->have_posts() ) : $loop02->the_post();
?>