Don’t really get what your main issue.. are you try to comparing two post types and display it in a page template? or are you try to comparing the current page with the selected post types?
try this create a page template
<?php
/*
* Template Name: Compare
*/
?>
<?php
get_header();
?>
<form id="customsearch" action="" method="post">
<select name="compare-one" id="compare-one">
<option value="130">1</option>
<option value="102">2</option>
</select>
<select name="compare-two" id="compare-two">
<option value="130">1</option>
<option value="102">2</option>
</select>
</form>
<script type="text/javascript">
$(document).ready(function() {
$('#compare-one').change(function() {
var compareone_value = $('#compare-one').val();
var data = {
'action':'callback_function',
'compare-one':compareone_value,
};
$.post(ajax_object.ajaxurl, data, function(response) {
$('#compare-one-container').html(response);
});
});
$('#compare-two').change(function() {
var comparetwo_value = $('#compare-two').val();
var data = {
'action':'callback_function',
'compare-two':comparetwo_value,
};
$.post(ajax_object.ajaxurl, data, function(response) {
$('#compare-two-container').html(response);
});
});
});
</script>
<div id="compare-container">
<div id="compare-one-container">
</div>
<div id="compare-two-container">
</div>
</div>
<?php get_footer(); ?>
next add a callback function to your functions.php
add_action('wp_ajax_callback_function', 'callback_function');
add_action('wp_ajax_nopriv_callback_function', 'callback_function'); // for not logged in user
function callback_function() {
if (isset($_POST['compare-one']) || isset($_POST['compare-two'])) {
$arr_id = array($_POST['compare-one'],$_POST['compare-two']);
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query(array('post_type' => 'listing', 'posts_per_page' => 2, 'post__in' => $arr_id));
while ($wp_query->have_posts()) : $wp_query->the_post();
$custom = get_post_custom($post->ID);
$beds = $custom['_beds'][0];
$baths = $custom['_baths'][0];
apply_filters('the_title', the_title());
apply_filters('the_content', the_content());
endwhile;
$wp_query = null; $wp_query = $temp;
rewind_posts();
}
die();
}
?>
and don’t forget to localize WordPress ajax script to use in front page
wp_enqueue_script( 'ajax-script', 'ajax_object', array('jquery'));
wp_localize_script( 'ajax-script', 'ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); // setting