I’d go with @Vinicius’ answer with the following changes:
-
Change
type: 'GET'
totype: 'POST'
-
Change
ajax: 1
toaction: 'filter_posts'
-
Replace
add_action('init', 'check_ajax');
with:add_action(‘wp_ajax_filter_posts’, ‘check_ajax’);
add_action(‘wp_ajax_nopriv_filter_posts’, ‘check_ajax’); -
Remove:
if (!isset($_POST[‘ajax’]))
return false;