質問編集履歴

1

試したコードを追加しました。

2019/06/14 08:47

投稿

Masahiko0055
Masahiko0055

スコア13

test CHANGED
File without changes
test CHANGED
@@ -42,6 +42,62 @@
42
42
 
43
43
 
44
44
 
45
+ ### 試したコード①
46
+
47
+
48
+
49
+ ```php
50
+
51
+ function empty_search( $query ) {
52
+
53
+ if ( $query->is_main_query() && $query->is_search && ! $query->is_admin ) {
54
+
55
+ $s = $query->get( 'search_keywords' );
56
+
57
+ $s = str_replace(' ',' ', $s );
58
+
59
+ $query->set( 'search_keywords', $s );
60
+
61
+ }
62
+
63
+ }
64
+
65
+ add_action( 'pre_get_posts', 'empty_search' );
66
+
67
+ ```
68
+
69
+
70
+
71
+ ### 試したコード②
72
+
73
+ ```php
74
+
75
+ function empty_search( $query ) {
76
+
77
+ if ( $query->is_main_query() && $query->is_search && ! $query->is_admin ) {
78
+
79
+ $search_keywords = $query->get( 'search_keywords' );
80
+
81
+ $search_keywords = str_replace(' ',' ', $search_keywords );
82
+
83
+ $query->set( 'search_keywords', $search_keywords );
84
+
85
+ }
86
+
87
+ }
88
+
89
+ add_action( 'pre_get_posts', 'empty_search' );
90
+
91
+ ```
92
+
93
+
94
+
95
+ 以上でも動作しませんでした。
96
+
97
+
98
+
99
+
100
+
45
101
 
46
102
 
47
103
  # 教えていただきたいこと