質問編集履歴

3

書式の改善

2019/07/26 08:35

投稿

sou_note
sou_note

スコア7

test CHANGED
File without changes
test CHANGED
@@ -78,7 +78,7 @@
78
78
 
79
79
  if ( $query->is_search() && $query->is_main_query() && ! is_admin() ) {
80
80
 
81
- $query->set( 'post_type', array( 'lawerlist' ) );
81
+ $query->set( 'post_type', array( '(カスタム投稿タイプ名)' ) );
82
82
 
83
83
  }
84
84
 

2

書式の改善

2019/07/26 08:34

投稿

sou_note
sou_note

スコア7

test CHANGED
File without changes
test CHANGED
@@ -30,11 +30,11 @@
30
30
 
31
31
  ### サイト内検索(2つ目)の記述
32
32
 
33
- <form method="get" id="blogSearch" action="<?php echo home_url('/'); ?>">
33
+ <form method="get" id="textsearch" action="<?php echo home_url('/'); ?>">
34
34
 
35
- <input type="text" name="s" id="blogSearchInput" value="<?php the_search_query(); ?>" placeholder="キーワードを入力してください。" />
35
+ <input type="text" name="s" id="textsearch" value="<?php the_search_query(); ?>" placeholder="キーワードを入力してさい。" />
36
36
 
37
- <input type="hidden" name="(ポストタイプ名)" value="blog">
37
+ <input type="hidden" name="post_type" value="(カスタム投稿タイプ名)">
38
38
 
39
39
  <input type="submit" value="検索" accesskey="f" />
40
40
 
@@ -65,3 +65,23 @@
65
65
  return $template;
66
66
 
67
67
  }
68
+
69
+
70
+
71
+ ### 補足
72
+
73
+ functions.phpに下記を記載したところ、2つ目の検索結果の条件絞り込みができましたが、
74
+
75
+ 1つ目も同様に反映されてしまいました。
76
+
77
+ function filter_search( $query ) {
78
+
79
+ if ( $query->is_search() && $query->is_main_query() && ! is_admin() ) {
80
+
81
+ $query->set( 'post_type', array( 'lawerlist' ) );
82
+
83
+ }
84
+
85
+ }
86
+
87
+ add_filter( 'pre_get_posts', 'filter_search' );

1

タグの追加

2019/07/26 08:34

投稿

sou_note
sou_note

スコア7

test CHANGED
File without changes
test CHANGED
File without changes