質問編集履歴
4
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -160,7 +160,7 @@
|
|
160
160
|
|
161
161
|
必要な関数(WordPressの関数、``get_my_query``、``get_favorite_userid``)を読み込もうとしたのですが、この書き方は間違っているでしょうか?それとも別の部分の問題でしょうか?
|
162
162
|
|
163
|
-
▼【lo
|
163
|
+
▼【load.php】
|
164
164
|
|
165
165
|
```php
|
166
166
|
|
3
試したこと
test
CHANGED
File without changes
|
test
CHANGED
@@ -78,7 +78,7 @@
|
|
78
78
|
|
79
79
|
|
80
80
|
|
81
|
-
<?php
|
81
|
+
<?php // 記事一覧のループ
|
82
82
|
|
83
83
|
$my_query = get_my_query( get_favorite_userid( get_current_user_id() ) );
|
84
84
|
|
@@ -158,9 +158,41 @@
|
|
158
158
|
|
159
159
|
### 試したこと
|
160
160
|
|
161
|
-
|
161
|
+
必要な関数(WordPressの関数、``get_my_query``、``get_favorite_userid``)を読み込もうとしたのですが、この書き方は間違っているでしょうか?それとも別の部分の問題でしょうか?
|
162
|
-
|
162
|
+
|
163
|
-
|
163
|
+
▼【loop-post.php】
|
164
|
+
|
165
|
+
```php
|
166
|
+
|
167
|
+
<p>load.phpのファイルを読み込みました。</p>
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
<?php // 必要な関数の読み込み
|
172
|
+
|
173
|
+
require_once( dirname(dirname( __FILE__ )) . '/wp-load.php' );
|
174
|
+
|
175
|
+
require_once( 'http://example.com/wp-content/themes/twentyseventeen-child/functions.php' );
|
176
|
+
|
177
|
+
?>
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
<?php // 記事一覧のループ
|
182
|
+
|
183
|
+
$my_query = get_my_query( get_favorite_userid( get_current_user_id() ) );
|
184
|
+
|
185
|
+
include locate_template( 'template-parts/loop-post.php' );
|
186
|
+
|
187
|
+
/* $my_queryにはループ条件が取得され、正常に作動します。 */
|
188
|
+
|
189
|
+
?>
|
190
|
+
|
191
|
+
```
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
164
196
|
|
165
197
|
### 補足情報(FW/ツールのバージョンなど)
|
166
198
|
|
2
タグ
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
1
補足
test
CHANGED
File without changes
|
test
CHANGED
@@ -84,7 +84,7 @@
|
|
84
84
|
|
85
85
|
include locate_template( 'template-parts/loop-post.php' );
|
86
86
|
|
87
|
-
/* $my_query
|
87
|
+
/* $my_queryにはループ条件が取得され、正常に作動します。 */
|
88
88
|
|
89
89
|
?>
|
90
90
|
|
@@ -94,7 +94,65 @@
|
|
94
94
|
|
95
95
|
宜しくお願い致します。
|
96
96
|
|
97
|
+
###補足
|
97
98
|
|
99
|
+
上の【load.php】について補足します。
|
100
|
+
|
101
|
+
``$my_query``には``get_my_query``によってループ条件が取得され、その条件が【loop-post.php】に引き継がれて記事一覧が取得されます。次の流れです。
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
▼【functions.php】
|
106
|
+
|
107
|
+
```php
|
108
|
+
|
109
|
+
// 記事を取得する相手を指定
|
110
|
+
|
111
|
+
function get_my_query( $userId ){
|
112
|
+
|
113
|
+
$args = array(
|
114
|
+
|
115
|
+
'posts_per_page' => 20,
|
116
|
+
|
117
|
+
'post_type' => array('post'),
|
118
|
+
|
119
|
+
'author' => $userId
|
120
|
+
|
121
|
+
);
|
122
|
+
|
123
|
+
$my_query = new WP_Query( $args );
|
124
|
+
|
125
|
+
return $my_query;
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
```
|
130
|
+
|
131
|
+
▼【loop-post.php】
|
132
|
+
|
133
|
+
```php
|
134
|
+
|
135
|
+
<ul>
|
136
|
+
|
137
|
+
<?php if ( $my_query->have_posts() ) : ?>
|
138
|
+
|
139
|
+
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
|
140
|
+
|
141
|
+
<li><?php the_title();?></li>
|
142
|
+
|
143
|
+
<?php endwhile; ?>
|
144
|
+
|
145
|
+
</ul>
|
146
|
+
|
147
|
+
<?php wp_reset_postdata(); ?>
|
148
|
+
|
149
|
+
<?php else : ?>
|
150
|
+
|
151
|
+
<p>記事なし</p>
|
152
|
+
|
153
|
+
<?php endif; ?>
|
154
|
+
|
155
|
+
```
|
98
156
|
|
99
157
|
|
100
158
|
|