javascript variable to wordpress php variable

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’)) );


var compareIDs = $(“.table td input:checkbox:checked”).map(function(){
return $(this).val();
}).get(); // <—-

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


$compareIDs = array( $_POST[‘compareIDs’] );

$args02 = array( ‘post_type’ => ‘custom’,
‘post__in’ => $compareIDs );

$loop02 = new WP_Query( $args02 );

while ( $loop02->have_posts() ) : $loop02->the_post();

Read more here:: javascript variable to wordpress php variable

Leave a Reply

Your email address will not be published. Required fields are marked *