<form action="/wp-admin/admin-ajax.php" method="POST" id="filter">
<select name="post-filters"><option value="">Select post_type</option>
<option value="first_post_type">first_post_type</option>
<option value="second_first_type">second_first_type</option>
</select>
<button>Apply</button>
<input type="hidden" name="action" value="myfilter">
</form>
<div id="response"></div>
<script>
jQuery(function($){
$('#filter').submit(function(){
var filter = $('#filter');
$.ajax({
url:filter.attr('action'),
data:filter.serialize(),
type:filter.attr('method'),
beforeSend:function(xhr){
filter.find('button').text('Processing...');
},
success:function(data){
filter.find('button').text('Apply filter');
$('#response').html(data);
}
});
return false;
});
});
</script>
add_action('wp_ajax_postfilter', 'function_filter');
add_action('wp_ajax_myfilter', 'function_filter');
function function_filter(){
if( isset( $_POST['post-filters'] ) )
$args['tax_query'] = array(
array(
'taxonomy' => 'new_tax',
'field' => 'id',
'post_type' => $_POST['post-filters']
)
);
$query = new WP_Query( $args );
if( $query->have_posts() ) :
while( $query->have_posts() ): $query->the_post();
echo '<h4>' . $query->post->post_title . '</h4>';
endwhile;
wp_reset_postdata();
else :
echo 'No posts found';
endif;
die();
}
Array (
[items] => Array (
[0] => Array (
[id] => 791
[from_id] => 4092108
[to_id] => 4092108
[date] => 1560265172
[post_type] => post
[text] =>
[copy_history] => Array (
[0] => Array (
[id] => 4637
[owner_id] => -758967
[from_id] => -758967
[date] => 1560175291
[post_type] => post
[text] => текст поста
[attachments] => Array (
[0] => Array (
[type] => photo
[photo] => Array (
[id] => 4562433
[album_id] => -7
[owner_id] => -758967
[user_id] => 100
[sizes] => Array (
[0] => Array (
[type] => m [url] => https://pp.userapi.com/c854128/v854128765/664de/i9AuN2Fnk.jpg
[width] => 130
[height] => 86
)
[1] => Array (
[type] => o
[url] => https://pp.userapi.com/c854128/v854128765/664e0/9zu0Q_EeM.jpg
[width] => 130
[height] => 87
)
[2] => Array (
[type] => p
[url] => https://pp.userapi.com/c854128/v854128765/664e1/CQkNEogA.jpg
[width] => 200
[height] => 133
)
[3] => Array (
[type] => q
[url] => https://pp.userapi.com/c854128/v854128765/664e2/8IxnCJCMg.jpg
[width] => 320
[height] => 213
)
[4] => Array (
[type] => r
[url] => https://pp.userapi.com/c854128/v854128765/664e3/l7NOBlsOU.jpg
[width] => 510
[height] => 340
)
[5] => Array (
[type] => s
[url] => https://pp.userapi.com/c854128/v854128765/664dd/STLzERbLI.jpg
[width] => 75
[height] => 50
)
[6] => Array (
[type] => x
[url] => https://pp.userapi.com/c854128/v854128765/664df/CqqpxEcHg.jpg
[width] => 585
[height] => 389
)
)
[text] =>
[date] => 1560178731
[access_key] => 450a267bb30f7
)
)
)
[post_source] => Array (
[type] => vk
)
)
)
[post_source] => Array (
[type] => vk
)
[comments] => Array (
[count] => 0
[can_post] => 1
[groups_can_post] => 1
)
[likes] => Array (
[count] => 0
[user_likes] => 0
[can_like] => 1
[can_publish] => 1
)
[reposts] => Array (
[count] => 0
[
user_reposted] => 0
)
[views] => Array (
[count] => 10
)
[is_favorite] =>
)
)
[profiles] => Array (
[0] => Array (
[id] => 409210
[first_name] => Имя
[last_name] => Фамилия
[is_closed] =>
[can_access_closed] => 1
[sex] => 1
[screen_name] => id4092108
[photo_50] => https://pp.userapi.com/c636631/v636631873/4e074/ZTCyE3y3c.jpg?ava=1
[photo_100] => https://pp.userapi.com/c636631/v636631873/4e073/rW3GGGpRg.jpg?ava=1
[online] => 0
)
)
[groups] => Array (
[0] => Array (
[id] => 758967
[name] => test
[screen_name] => ugfuigfcuyg
[is_closed] => 0
[type] => group
[is_admin] => 1
[admin_level] => 3
[is_member] => 1
[is_advertiser] => 1
[photo_50] => https://sun1-85.userapi.com/c638127/v638127093/55fbb/LZ3FFZQI.jpg?ava=1
[photo_100] => https://sun1-86.userapi.com/c638127/v638127093/55fba/G2U_r0yY.jpg?ava=1
[photo_200] => https://sun1-15.userapi.com/c638127/v638127093/55fb9/ZSeET-J0.jpg?ava=1
)
)
)
1