我需要对2个不同的页面执行2个不同的搜索 这是第一个,第二个将是每页10个帖子,不同的帖子类型,我尝试使用is_page(),但是由于它抛出0个结果,所以我不起作用,而且我已经检查了是否有
function ja_ajax_search() {
$results = new WP_Query( array(
'post_type' => array( 'post', 'page' ),
'posts_per_page' => 5,
's' => stripslashes( $_POST['search'] ),
) );
$items = array();
if ( ! empty( $results->posts ) ) {
foreach ( $results->posts as $result ) {
$items[] = $result->post_title;
}
}
wp_send_json_success( $items );
}
add_action( 'wp_ajax_search_site', 'ja_ajax_search' );
add_action( 'wp_ajax_nopriv_search_site', 'ja_ajax_search' );
/*eslint-disable */
jQuery(function ($) {
var searchRequest;
$('#ses').autoComplete({
minChars: 3,
source: function (term, suggest) {
searchRequest = $.post(global.ajax, {search: term, action: 'search_site',tip_pretrage: 'cards'}, function (res) {
suggest(res.data);
});
},
})
});