-
Notifications
You must be signed in to change notification settings - Fork 0
/
php-ajax-response-example.php
45 lines (30 loc) · 1.13 KB
/
php-ajax-response-example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
class agAjaxes {
public function __construct() {
add_action('template_redirect', array($this,'ag_search_ajax'));
}
public function ag_search_ajax(){
global $wp_query;
$method = $wp_query->get('rewrite_search_ajax');
if (!$method) {
return;
}
if($method === 'search1'):
$ss = esc_attr( $_POST['keyword'] );
$the_query = new WP_Query( array( 'posts_per_page' => 3, 's' => esc_attr( $_POST['keyword'] ), 'post_type' => array('product') ) );
if( $the_query->have_posts() ) :
while( $the_query->have_posts() ): $the_query->the_post(); ?>
<?php endwhile;
if($the_query->found_posts > 3){
?>
<?php
}elseif($the_query->found_posts == 0){
?>
<?php
}
wp_reset_postdata();
endif;
endif;
die();
}
}