質問編集履歴

6

修正

2018/05/10 07:43

投稿

kinakomochi
kinakomochi

スコア24

test CHANGED
File without changes
test CHANGED
@@ -15,7 +15,3 @@
15
15
  Fatal error: Uncaught Error: Call to undefined function get_filed() in /home/test/www/elc2/wp/wp-content/themes/elc/search.php:75 Stack trace: #0 /home/test/www/elc2/wp/wp-content/themes/elc/functions.php(76): include() #1 /home/test/www/elc2/wp/wp-includes/class-wp-hook.php(286): search_no_keywords('') #2 /home/test/www/elc2/wp/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #3 /home/test/www/elc2/wp/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #4 /home/test/www/elc2/wp/wp-includes/template-loader.php(12): do_action('template_redire...') #5 /home/test/www/elc2/wp/wp-blog-header.php(19): require_once('/home/test/www...') #6 /home/test/www/elc2/index.php(17): require('/home/test/www...') #7 {main} thrown in /home/test/www/elc2/wp/wp-content/themes/elc/search.php on line 75
16
16
 
17
17
  ```
18
-
19
-
20
-
21
- ちなみにfunctions.phpの76行目には下記サイトを参考にして、下記のようなコードを追加しております。

5

修正

2018/05/10 07:43

投稿

kinakomochi
kinakomochi

スコア24

test CHANGED
File without changes
test CHANGED
@@ -19,323 +19,3 @@
19
19
 
20
20
 
21
21
  ちなみにfunctions.phpの76行目には下記サイトを参考にして、下記のようなコードを追加しております。
22
-
23
-
24
-
25
- [参考サイト](http://kotori-blog.com/wordpress/refinement_search/)
26
-
27
-
28
-
29
- ```ここに言語を入力
30
-
31
- function search_no_keywords() {
32
-
33
- if (isset($_GET['s']) && empty($_GET['s'])) {
34
-
35
- //URLにパラメータ「s」がついていたらsearch.phpを表示
36
-
37
- include(TEMPLATEPATH . '/search.php');
38
-
39
- exit;
40
-
41
- }
42
-
43
- }
44
-
45
- add_action('template_redirect', 'search_no_keywords');
46
-
47
- ```
48
-
49
-
50
-
51
- 追記
52
-
53
- ==
54
-
55
- プラグインは「Advanced Custom Fields」を使用し追加しております。
56
-
57
- また、プラグイン「User Role Editor」でユーザーごとの権限の設定や、functions.phpに他のユーザーが投稿したものを触れないように設定しております。
58
-
59
- ```ここに言語を入力
60
-
61
- /*-------------------------------------------*/
62
-
63
- /*【管理画面】投稿一覧で他のユーザーが投稿した投稿を非表示
64
-
65
- /*-------------------------------------------*/
66
-
67
- function posts_for_current_author($query) {
68
-
69
- global $user_level;
70
-
71
-
72
-
73
- if($query->is_admin && $user_level < 5) {
74
-
75
- global $user_ID;
76
-
77
- $query->set('author', $user_ID);
78
-
79
- unset($user_ID);
80
-
81
- }
82
-
83
- unset($user_level);
84
-
85
-
86
-
87
- return $query;
88
-
89
- }
90
-
91
- add_filter('pre_get_posts', 'posts_for_current_author');
92
-
93
-
94
-
95
- /*-------------------------------------------*/
96
-
97
- /*【管理画面】投稿一覧で他のユーザーが投稿した画像を非表示
98
-
99
- /*-------------------------------------------*/
100
-
101
- function display_only_self_uploaded_medias( $query ) {
102
-
103
- if ( ( $user = wp_get_current_user() ) && ! current_user_can( 'administrator' || 'e-learning' ) ) {
104
-
105
- $query['author'] = $user->ID;
106
-
107
- }
108
-
109
- return $query;
110
-
111
- }
112
-
113
- add_action( 'ajax_query_attachments_args', 'display_only_self_uploaded_medias' );
114
-
115
-
116
-
117
- ```
118
-
119
-
120
-
121
- ■search.php
122
-
123
- ```ここに言語を入力
124
-
125
- <?php get_header(); ?>
126
-
127
-
128
-
129
- <?php
130
-
131
- $s = $_GET['s'];
132
-
133
- $item_tag = $_GET['item'];
134
-
135
- $genre_tag = $_GET['genre'];
136
-
137
- $type_tag = $_GET['type'];
138
-
139
-
140
-
141
- // 配列「ジャンル選択」から空要素を削除
142
-
143
- $genre_tag = array_filter($genre_tag, "strlen");
144
-
145
-
146
-
147
- // 配列「タイプ選択」から空要素を削除
148
-
149
- $type_tag = array_filter($type_tag, "strlen");
150
-
151
-
152
-
153
- //tax_query用
154
-
155
- if($item_tag){
156
-
157
- $taxquerysp[] = array(
158
-
159
- 'post_type' => 'member',
160
-
161
- 'taxonomy'=>'ctcategory',
162
-
163
- 'terms'=> $item_tag,
164
-
165
- 'include_children'=>false,
166
-
167
- 'field'=>'slug',
168
-
169
- 'operator'=>'AND'
170
-
171
- );
172
-
173
- $item_name = get_term_by( 'slug', $item_tag, 'ctcategory' );
174
-
175
- }
176
-
177
- if($genre_tag){
178
-
179
- $taxquerysp[] = array(
180
-
181
- 'post_type' => 'member',
182
-
183
- 'taxonomy'=>'ctcategory',
184
-
185
- 'terms'=> $genre_tag,
186
-
187
- 'include_children'=>false,
188
-
189
- 'field'=>'slug',
190
-
191
- 'operator'=>'AND'
192
-
193
- );
194
-
195
- $genre_name = get_term_by( 'slug', $genre_tag, 'ctcategory' );
196
-
197
- }
198
-
199
- if($type_tag){
200
-
201
- $taxquerysp[] = array(
202
-
203
- 'post_type' => 'member',
204
-
205
- 'taxonomy'=>'ctcategory',
206
-
207
- 'terms'=> $type_tag,
208
-
209
- 'include_children'=>false,
210
-
211
- 'field'=>'slug',
212
-
213
- 'operator'=>'AND'
214
-
215
- );
216
-
217
- $type_name = get_term_by( 'slug', $type_tag, 'ctcategory' );
218
-
219
- }
220
-
221
-
222
-
223
- $args = array(
224
-
225
- 'tax_query' => $taxquerysp,
226
-
227
- 's' => $s,
228
-
229
- );
230
-
231
- $the_query = new WP_Query( $args );
232
-
233
- ?>
234
-
235
- <div id="container" class="testContent clear">
236
-
237
- <div id="main">
238
-
239
- <h1>検索キーワード</h1>
240
-
241
- <?php
242
-
243
- $count = $the_query->post_count;
244
-
245
- if($count!=0){
246
-
247
- echo '<p class="searchCount">検索結果 '.$count.'件</p>';
248
-
249
- }
250
-
251
- ?>
252
-
253
- <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
254
-
255
- <article class="contentList">
256
-
257
- <div class="clear">
258
-
259
- <div class="leftImg">
260
-
261
- <p>
262
-
263
- <?php the_title() ?>
264
-
265
- </p>
266
-
267
- <?php
268
-
269
- // カスタムフィールド値取得
270
-
271
- // 「コンテンツ1_画像」に設定した画像取得
272
-
273
- $c_img = get_filed("cf1_img");
274
-
275
- // 「コンテンツ1_見出し」に設定した画像取得
276
-
277
- $c_title = get_filed("cf1_title");
278
-
279
- // 「コンテンツ1_テキスト」に設定した画像取得
280
-
281
- $c_txt = get_filed("cf1_txt");
282
-
283
- ?>
284
-
285
- <?php echo $c_img ?>
286
-
287
-
288
-
289
- <?php if($c_img): ?>
290
-
291
- <img src="<?php echo $c_img ?>" alt="<?php the_title() ?>">
292
-
293
- <?php else: ?>
294
-
295
- <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/common/no-image.png" alt="">
296
-
297
- <?php endif; ?>
298
-
299
- </div>
300
-
301
- <div class="rightTxt">
302
-
303
- <h2><?php echo $c_title ?></h2>
304
-
305
- <?php echo $c_txt ?>
306
-
307
- </div>
308
-
309
- </div>
310
-
311
- <a href="<?php the_permalink(); ?>"></a>
312
-
313
- </article>
314
-
315
- <?php endwhile; else : ?>
316
-
317
-
318
-
319
- <div class="notContent">関連する記事は見つかりませんでした。</div>
320
-
321
-
322
-
323
- <?php endif;
324
-
325
- wp_reset_postdata(); ?>
326
-
327
- </div><!-- #main -->
328
-
329
- <?php get_sidebar(); ?>
330
-
331
- </div><!-- #container -->
332
-
333
-
334
-
335
-
336
-
337
- <?php get_footer(); ?>
338
-
339
-
340
-
341
- ```

4

情報追加

2018/05/10 07:43

投稿

kinakomochi
kinakomochi

スコア24

test CHANGED
File without changes
test CHANGED
@@ -115,3 +115,227 @@
115
115
 
116
116
 
117
117
  ```
118
+
119
+
120
+
121
+ ■search.php
122
+
123
+ ```ここに言語を入力
124
+
125
+ <?php get_header(); ?>
126
+
127
+
128
+
129
+ <?php
130
+
131
+ $s = $_GET['s'];
132
+
133
+ $item_tag = $_GET['item'];
134
+
135
+ $genre_tag = $_GET['genre'];
136
+
137
+ $type_tag = $_GET['type'];
138
+
139
+
140
+
141
+ // 配列「ジャンル選択」から空要素を削除
142
+
143
+ $genre_tag = array_filter($genre_tag, "strlen");
144
+
145
+
146
+
147
+ // 配列「タイプ選択」から空要素を削除
148
+
149
+ $type_tag = array_filter($type_tag, "strlen");
150
+
151
+
152
+
153
+ //tax_query用
154
+
155
+ if($item_tag){
156
+
157
+ $taxquerysp[] = array(
158
+
159
+ 'post_type' => 'member',
160
+
161
+ 'taxonomy'=>'ctcategory',
162
+
163
+ 'terms'=> $item_tag,
164
+
165
+ 'include_children'=>false,
166
+
167
+ 'field'=>'slug',
168
+
169
+ 'operator'=>'AND'
170
+
171
+ );
172
+
173
+ $item_name = get_term_by( 'slug', $item_tag, 'ctcategory' );
174
+
175
+ }
176
+
177
+ if($genre_tag){
178
+
179
+ $taxquerysp[] = array(
180
+
181
+ 'post_type' => 'member',
182
+
183
+ 'taxonomy'=>'ctcategory',
184
+
185
+ 'terms'=> $genre_tag,
186
+
187
+ 'include_children'=>false,
188
+
189
+ 'field'=>'slug',
190
+
191
+ 'operator'=>'AND'
192
+
193
+ );
194
+
195
+ $genre_name = get_term_by( 'slug', $genre_tag, 'ctcategory' );
196
+
197
+ }
198
+
199
+ if($type_tag){
200
+
201
+ $taxquerysp[] = array(
202
+
203
+ 'post_type' => 'member',
204
+
205
+ 'taxonomy'=>'ctcategory',
206
+
207
+ 'terms'=> $type_tag,
208
+
209
+ 'include_children'=>false,
210
+
211
+ 'field'=>'slug',
212
+
213
+ 'operator'=>'AND'
214
+
215
+ );
216
+
217
+ $type_name = get_term_by( 'slug', $type_tag, 'ctcategory' );
218
+
219
+ }
220
+
221
+
222
+
223
+ $args = array(
224
+
225
+ 'tax_query' => $taxquerysp,
226
+
227
+ 's' => $s,
228
+
229
+ );
230
+
231
+ $the_query = new WP_Query( $args );
232
+
233
+ ?>
234
+
235
+ <div id="container" class="testContent clear">
236
+
237
+ <div id="main">
238
+
239
+ <h1>検索キーワード</h1>
240
+
241
+ <?php
242
+
243
+ $count = $the_query->post_count;
244
+
245
+ if($count!=0){
246
+
247
+ echo '<p class="searchCount">検索結果 '.$count.'件</p>';
248
+
249
+ }
250
+
251
+ ?>
252
+
253
+ <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
254
+
255
+ <article class="contentList">
256
+
257
+ <div class="clear">
258
+
259
+ <div class="leftImg">
260
+
261
+ <p>
262
+
263
+ <?php the_title() ?>
264
+
265
+ </p>
266
+
267
+ <?php
268
+
269
+ // カスタムフィールド値取得
270
+
271
+ // 「コンテンツ1_画像」に設定した画像取得
272
+
273
+ $c_img = get_filed("cf1_img");
274
+
275
+ // 「コンテンツ1_見出し」に設定した画像取得
276
+
277
+ $c_title = get_filed("cf1_title");
278
+
279
+ // 「コンテンツ1_テキスト」に設定した画像取得
280
+
281
+ $c_txt = get_filed("cf1_txt");
282
+
283
+ ?>
284
+
285
+ <?php echo $c_img ?>
286
+
287
+
288
+
289
+ <?php if($c_img): ?>
290
+
291
+ <img src="<?php echo $c_img ?>" alt="<?php the_title() ?>">
292
+
293
+ <?php else: ?>
294
+
295
+ <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/common/no-image.png" alt="">
296
+
297
+ <?php endif; ?>
298
+
299
+ </div>
300
+
301
+ <div class="rightTxt">
302
+
303
+ <h2><?php echo $c_title ?></h2>
304
+
305
+ <?php echo $c_txt ?>
306
+
307
+ </div>
308
+
309
+ </div>
310
+
311
+ <a href="<?php the_permalink(); ?>"></a>
312
+
313
+ </article>
314
+
315
+ <?php endwhile; else : ?>
316
+
317
+
318
+
319
+ <div class="notContent">関連する記事は見つかりませんでした。</div>
320
+
321
+
322
+
323
+ <?php endif;
324
+
325
+ wp_reset_postdata(); ?>
326
+
327
+ </div><!-- #main -->
328
+
329
+ <?php get_sidebar(); ?>
330
+
331
+ </div><!-- #container -->
332
+
333
+
334
+
335
+
336
+
337
+ <?php get_footer(); ?>
338
+
339
+
340
+
341
+ ```

3

情報追加

2018/05/08 07:02

投稿

kinakomochi
kinakomochi

スコア24

test CHANGED
File without changes
test CHANGED
@@ -45,3 +45,73 @@
45
45
  add_action('template_redirect', 'search_no_keywords');
46
46
 
47
47
  ```
48
+
49
+
50
+
51
+ 追記
52
+
53
+ ==
54
+
55
+ プラグインは「Advanced Custom Fields」を使用し追加しております。
56
+
57
+ また、プラグイン「User Role Editor」でユーザーごとの権限の設定や、functions.phpに他のユーザーが投稿したものを触れないように設定しております。
58
+
59
+ ```ここに言語を入力
60
+
61
+ /*-------------------------------------------*/
62
+
63
+ /*【管理画面】投稿一覧で他のユーザーが投稿した投稿を非表示
64
+
65
+ /*-------------------------------------------*/
66
+
67
+ function posts_for_current_author($query) {
68
+
69
+ global $user_level;
70
+
71
+
72
+
73
+ if($query->is_admin && $user_level < 5) {
74
+
75
+ global $user_ID;
76
+
77
+ $query->set('author', $user_ID);
78
+
79
+ unset($user_ID);
80
+
81
+ }
82
+
83
+ unset($user_level);
84
+
85
+
86
+
87
+ return $query;
88
+
89
+ }
90
+
91
+ add_filter('pre_get_posts', 'posts_for_current_author');
92
+
93
+
94
+
95
+ /*-------------------------------------------*/
96
+
97
+ /*【管理画面】投稿一覧で他のユーザーが投稿した画像を非表示
98
+
99
+ /*-------------------------------------------*/
100
+
101
+ function display_only_self_uploaded_medias( $query ) {
102
+
103
+ if ( ( $user = wp_get_current_user() ) && ! current_user_can( 'administrator' || 'e-learning' ) ) {
104
+
105
+ $query['author'] = $user->ID;
106
+
107
+ }
108
+
109
+ return $query;
110
+
111
+ }
112
+
113
+ add_action( 'ajax_query_attachments_args', 'display_only_self_uploaded_medias' );
114
+
115
+
116
+
117
+ ```

2

追記

2018/05/08 06:57

投稿

kinakomochi
kinakomochi

スコア24

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- ちなみに下記コードは、「new WP_Query」で取得した物のループ内でカスタムフィールドを取得しようとして表示されております。
9
+ ちなみに下記コードは、「search.php」に「new WP_Query」で取得した物のループ内でカスタムフィールドを取得しようとして表示されております。
10
10
 
11
11
 
12
12
 

1

追記

2018/05/08 06:44

投稿

kinakomochi
kinakomochi

スコア24

test CHANGED
File without changes
test CHANGED
@@ -15,3 +15,33 @@
15
15
  Fatal error: Uncaught Error: Call to undefined function get_filed() in /home/test/www/elc2/wp/wp-content/themes/elc/search.php:75 Stack trace: #0 /home/test/www/elc2/wp/wp-content/themes/elc/functions.php(76): include() #1 /home/test/www/elc2/wp/wp-includes/class-wp-hook.php(286): search_no_keywords('') #2 /home/test/www/elc2/wp/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #3 /home/test/www/elc2/wp/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #4 /home/test/www/elc2/wp/wp-includes/template-loader.php(12): do_action('template_redire...') #5 /home/test/www/elc2/wp/wp-blog-header.php(19): require_once('/home/test/www...') #6 /home/test/www/elc2/index.php(17): require('/home/test/www...') #7 {main} thrown in /home/test/www/elc2/wp/wp-content/themes/elc/search.php on line 75
16
16
 
17
17
  ```
18
+
19
+
20
+
21
+ ちなみにfunctions.phpの76行目には下記サイトを参考にして、下記のようなコードを追加しております。
22
+
23
+
24
+
25
+ [参考サイト](http://kotori-blog.com/wordpress/refinement_search/)
26
+
27
+
28
+
29
+ ```ここに言語を入力
30
+
31
+ function search_no_keywords() {
32
+
33
+ if (isset($_GET['s']) && empty($_GET['s'])) {
34
+
35
+ //URLにパラメータ「s」がついていたらsearch.phpを表示
36
+
37
+ include(TEMPLATEPATH . '/search.php');
38
+
39
+ exit;
40
+
41
+ }
42
+
43
+ }
44
+
45
+ add_action('template_redirect', 'search_no_keywords');
46
+
47
+ ```