‘post_type’ => array( ‘post’, ‘page’, ‘wp_block’ ) ,
に設定すれば可能なのだが、function.phpに記述すると何故かadminページで検索ができなくなった。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
function my_sort_order_by_modifired ( $query ) { $query->set( 'order', 'DESC' ); $query->set( 'orderby', 'modified' ); if ( $query->is_search ) { $query->set( 'post_type', array( 'post', 'page', 'wp_block' ) ); }else{ $query->set( 'post_type', 'post' ); } } add_action( 'pre_get_posts', 'my_sort_order_by_modifired' ); |
これがうまく行かないので直接searchwp-live-ajax-searchプラグインを修正。
searchwp-live-ajax-search\includes\class-client.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 |
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(); } |
つまり
‘post_type’ => array( ‘post’, ‘page’, ‘wp_block’ ) ,
これをプラグインの方に記述しました。
wp_block が再利用可能ブロック。
SearchWP
を使うともしかしてできるのかもしれないですが、有料のようなので未検証です。
仕方なく直接プラグインをいじることになりました。