Benutzerdefinierte Suchfelder und AJAX-Unterstützung

Ich versuche die Suche umzuschreiben. Ich habe die Aktion pre_get_posts und die Filter posts_where und posts_join . Die Seite wird mit meinen benutzerdefinierten Filtern geladen. Aber ich kann es nicht mit AJAX arbeiten lassen. Wie kann ich es zum Laufen bringen? Die Aktion und die Filter sind wahrscheinlich nicht trigerred.

Code der Filter

 function search_filter_where( $where = '' ) { global $wpdb; if(is_main_query() && is_search()) { if(get_query_var('a_lyon')) { $where .= " AND (sp_pm1.meta_key = 'post_code' AND sp_pm1.meta_value BETWEEN '69000' AND '69009') "; } if(get_query_var('autour_de_lyon')) { $where .= " AND (sp_pm2.meta_key = 'post_code' AND sp_pm2.meta_value BETWEEN '69000' AND '69999' OR sp_pm2.meta_key = 'post_code' AND sp_pm2.meta_value BETWEEN '38200' AND '38299') "; } if(get_query_var('when') && get_query_var('when') != '') { $time = strtotime(get_query_var('when')); if($time != -1) { $date = date('Ym-d', $time); $where .= " AND ({$wpdb->posts}.post_date BETWEEN '{$date} 00:00:00' AND '{$date} 23:59:59') "; } } if(get_query_var('gratuit')) { $where .= " AND (sp_pm3.meta_key = 'price' AND (sp_pm3.meta_value IS NULL OR wp_postmeta.meta_value = 0 OR wp_postmeta.meta_value = '')) "; } } return $where; } add_filter('posts_where', 'search_filter_where'); function search_posts_join( $join = '' ) { global $wpdb; if(is_main_query() && is_search()) { if(get_query_var('a_lyon')) { $join .= " INNER JOIN $wpdb->postmeta sp_pm1 ON ({$wpdb->posts}.ID = sp_pm1.post_id) "; } if(get_query_var('autour_de_lyon')) { $join .= " INNER JOIN $wpdb->postmeta sp_pm2 ON ({$wpdb->posts}.ID = sp_pm2.post_id) "; } if(get_query_var('gratuit')) { $join .= " LEFT JOIN $wpdb->postmeta sp_pm3 ON ({$wpdb->posts}.ID = sp_pm3.post_id AND (wp_postmeta.meta_key IS NULL OR wp_postmeta.meta_key LIKE 'price')) "; } } return $join; } add_filter('posts_join','search_posts_join'); add_action( 'pre_get_posts', function( WP_Query $query ) { if (is_main_query() && $query->is_search()) { $meta_query = array('relation' => 'AND'); if(get_query_var('jeune_public')) $meta_query[] = array( 'key' => 'jeune_public', 'value' => '1', 'compare' => '=' ); if(get_query_var('gratuit')) $meta_query[] = array( 'key' => 'price', 'value' => array('', '0'), 'compare' => 'IN' ); if(get_query_var('location') && get_query_var('location') != '') $meta_query[] = array( 'key' => 'location', 'value' => get_query_var('location'), 'compare' => 'LIKE' ); $query->set('meta_query', $meta_query); } }); 

AJAX-Suchcode

 add_action( 'wp_ajax_search_posts', 'em_ajax_search_posts' ); add_action( 'wp_ajax_nopriv_search_posts', 'em_ajax_search_posts' ); function em_ajax_search_posts() { global $wp_query, $wpdb; $page = (int) $_GET['page']; $posts_per_page = get_option('posts_per_page'); $args = array( 'posts_per_page' => $posts_per_page, 'order' => 'DESC', 'paged' => $page, 's' => $_GET['s'], 'when' => $_GET['when'], 'location' => $_GET['location'], 'a_lyon' => $_GET['a_lyon'], ); $wp_query = new wp_query( $args ); echo get_template_part( 'page-templates/nillloop-stylefive' ); die; } 

Solutions Collecting From Web of "Benutzerdefinierte Suchfelder und AJAX-Unterstützung"