function search() {
if ( isset( $_REQUEST['swpquery'] ) && ! empty( $_REQUEST['swpquery'] ) ) {
$query = sanitize_text_field( stripslashes( $_REQUEST['swpquery'] ) );
if ( class_exists( 'SearchWP' ) ) {
// SearchWP powered search
$posts = $this->searchwp( $query );
// Normally we could use 'any' post type because we've already found our IDs
// but if you use 'any' WP_Query will still take into consideration exclude_from_search
// when we eventually run our query_posts() in $this->show_results() so we're
// going to rebuild our array from the engine configuration post types and use that.
$post_types = SWP()->get_enabled_post_types_across_all_engines();
$args = array(
'post_type' => $post_types,
'post_status' => 'any', // We're limiting to a pre-set array of post IDs.
'post__in' => $posts,
'orderby' => 'post__in',
'suppress_filters' => true,
);
} else {
// native WordPress search
$args = array(
's' => $query,
'post_status' => 'publish',
// 'post_type' => get_post_types( array(
// 'public' => true,
// 'exclude_from_search' => false,
// ) ), //20200720mod 再利用可能ブロックを検索対象に
'post_type' => array( 'post', 'page', 'wp_block' ) ,
);
}
$args['posts_per_page'] = $this->get_posts_per_page();
$args = apply_filters( 'searchwp_live_search_query_args', $args );
$this->show_results( $args );
}
// Short circuit to keep the overhead of an admin-ajax.php call to a minimum.
die();
}