質問編集履歴

6

code修正

2020/07/10 16:50

投稿

cwhiro
cwhiro

スコア21

test CHANGED
File without changes
test CHANGED
@@ -7,6 +7,8 @@
7
7
  <?php
8
8
 
9
9
  $week = date('Y-m-d', strtotime('+7days'));
10
+
11
+ $name= get_search_query();
10
12
 
11
13
  global $query_string;
12
14
 
@@ -42,11 +44,7 @@
42
44
 
43
45
 
44
46
 
45
- <?php $my_posts = get_posts($args_normal); ?>
47
+ <?php $my_posts = get_posts($args_normal);
46
-
47
- <?php foreach($my_posts as $post): setup_postdata($post);
48
-
49
-
50
48
 
51
49
 
52
50
 
@@ -54,16 +52,16 @@
54
52
 
55
53
  foreach( $my_posts as $post ) {
56
54
 
57
- $titles[] = get_the_title( $post->ID);
55
+ $title = get_the_title( $post->ID);
58
56
 
59
57
  }}
60
58
 
59
+ echo $title;
61
60
 
62
-
63
- foreach($titles as $title)
61
+ var_dump($my_posts);
64
-
65
- echo $title;
66
62
 
67
63
  ?>
68
64
 
65
+ <?php wp_reset_postdata(); ?>
66
+
69
67
  ```

5

誤字修正

2020/07/10 16:50

投稿

cwhiro
cwhiro

スコア21

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- 下記のコードで、絞り込みした検索結果は表示することができるのですが、$args_normalを使ってFOREACHができません。下記の例では、最初の1件のタイトルだけ表示されます。正しくFOREACHするにはどのようにすればよいでしょうか。
1
+ 下記のコードで、絞り込みした検索結果は表示することができるのですが、$args_normalを使ってFOREACHができません。下記の例では、該当するタイトルが1度だけでなく、何度も繰り返し表示されます。正しくFOREACHするにはどのようにすればよいでしょうか。
2
2
 
3
3
 
4
4
 

4

code修正

2020/07/10 16:25

投稿

cwhiro
cwhiro

スコア21

test CHANGED
File without changes
test CHANGED
@@ -48,7 +48,7 @@
48
48
 
49
49
 
50
50
 
51
- <?php
51
+
52
52
 
53
53
  if ( $my_posts ) {
54
54
 

3

code修正

2020/07/10 16:19

投稿

cwhiro
cwhiro

スコア21

test CHANGED
File without changes
test CHANGED
@@ -62,7 +62,7 @@
62
62
 
63
63
  foreach($titles as $title)
64
64
 
65
- echo $title </div>';
65
+ echo $title;
66
66
 
67
67
  ?>
68
68
 

2

code修正

2020/07/10 16:10

投稿

cwhiro
cwhiro

スコア21

test CHANGED
File without changes
test CHANGED
@@ -48,6 +48,8 @@
48
48
 
49
49
 
50
50
 
51
+ <?php
52
+
51
53
  if ( $my_posts ) {
52
54
 
53
55
  foreach( $my_posts as $post ) {

1

code修正

2020/07/10 16:04

投稿

cwhiro
cwhiro

スコア21

test CHANGED
File without changes
test CHANGED
@@ -42,7 +42,7 @@
42
42
 
43
43
 
44
44
 
45
- <?php $my_posts = get_posts($args_data3); ?>
45
+ <?php $my_posts = get_posts($args_normal); ?>
46
46
 
47
47
  <?php foreach($my_posts as $post): setup_postdata($post);
48
48