Elementor用JetSmartFiltersとの互換性
SearchWP は Elementor カスタム検索アーカイブテンプレート で動作しますが、JetSmartFilters はアーカイブクエリをハイジャックすることで SearchWP の結果を上書きします。
JetEngine リスティンググリッドの使用
JetEngine リスティンググリッドを使用して結果を表示する場合に SearchWP の結果を統合するには、このフックを使用できます。
All hooks should be added to your custom SearchWP Customizations Plugin.
| <?php | |
| // Integrate SearchWP with JetSmartFilters search using | |
| // JetEngine Listing Grid to display results. | |
| // @link https://searchwp.com/documentation/knowledge-base/compatibility-with-jetsmartfilters-for-elementor/ | |
| add_action( 'pre_get_posts', function( $wp_query ) { | |
| if ( | |
| ! isset( $wp_query->query['jet_smart_filters' ] ) | |
| || empty( $wp_query->query['s'] ) | |
| ) { | |
| return; | |
| } | |
| $swp_query = new \SWP_Query( array( | |
| 'engine' => 'default', | |
| 's' => $wp_query->query['s'], | |
| 'fields' => 'ids', | |
| 'nopaging' => true | |
| ) ); | |
| $results = ! empty( $swp_query->posts ) ? $swp_query->posts : array( 0 ); | |
| $wp_query->set( 'post__in', $results ); | |
| $wp_query->set( 'post_type', 'any' ); | |
| $wp_query->set( 'post_status', 'any' ); | |
| $wp_query->set( 'orderby', 'post__in' ); | |
| $wp_query->set( 'order', 'DESC' ); | |
| $wp_query->set( 's', false ); | |
| }, 9999 ); |
Elementor Pro アーカイブの使用
この問題が発生した場合、2 つのオプションがあります。アーカイブページで JetSmartFilters を使用していない場合は、次の WordPress 管理メニュー画面に移動できます: Elementor > JetSmartFilters Settings このチェックボックスのチェックを外します。
チェックを外したら、保存ボタンをクリックすると問題が解決します。
ただし、他のアーカイブページで JetSmartFilters を使用している場合は、代わりにこのスニペットを使用して、検索アーカイブページで JetSmartFilters を無効にすることができます。これにより、Elementor の検索アーカイブテンプレートのカスタマイズを使用し、Elementor アーカイブ投稿ウィジェットを使用して検索結果を表示できます。
これは簡単な修正です。このスニペットをテーマの functions.php (または作成したカスタムプラグイン) に追加すると、SearchWP の結果を表示できるようになります。
| <?php | |
| // Prevents JetSmartFilters from overriding SearchWP's results. | |
| // @link https://searchwp.com/documentation/knowledge-base/compatibility-with-jetsmartfilters-for-elementor/ | |
| add_action( 'init', function() { | |
| add_filter( 'elementor/theme/posts_archive/query_posts/query_vars', function( $query ) { | |
| if ( is_search() && is_main_query() ) { | |
| remove_all_filters( 'elementor/theme/posts_archive/query_posts/query_vars' ); | |
| } | |
| return $query; | |
| }, -1 ); | |
| }, -998 ); |
上記のスニペットは、Jet Smart Filter の内部フックの優先度を利用して、検索結果アーカイブページで SearchWP の結果が上書きされるのを防ぎます。


