質問編集履歴
1
kei344 さんのアドバイスにより解決しました!!
test
CHANGED
File without changes
|
test
CHANGED
@@ -123,3 +123,115 @@
|
|
123
123
|
|
124
124
|
|
125
125
|
よろしくお願いします。
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
### 解決コード
|
132
|
+
|
133
|
+
```
|
134
|
+
|
135
|
+
<!-- 新着記事を表示 -->
|
136
|
+
|
137
|
+
<?php
|
138
|
+
|
139
|
+
$args = array(
|
140
|
+
|
141
|
+
'post_type' => 'post',
|
142
|
+
|
143
|
+
'post_status' => 'publish',
|
144
|
+
|
145
|
+
'category_name' => 'カテゴリ',
|
146
|
+
|
147
|
+
'posts_per_page' => 6,
|
148
|
+
|
149
|
+
'fields' => 'ids'
|
150
|
+
|
151
|
+
);
|
152
|
+
|
153
|
+
$the_query = new WP_Query($args);
|
154
|
+
|
155
|
+
$post_ids = $the_query->posts; // 除外記事を取得
|
156
|
+
|
157
|
+
?>
|
158
|
+
|
159
|
+
<?php if($the_query->have_posts()): ?>
|
160
|
+
|
161
|
+
<?php while ($the_query->have_posts()): $the_query->the_post(); ?>
|
162
|
+
|
163
|
+
<!-- 投稿を表示 -->
|
164
|
+
|
165
|
+
<?php endwhile; ?>
|
166
|
+
|
167
|
+
<?php else: ?>
|
168
|
+
|
169
|
+
<!-- 投稿が無い場合 -->
|
170
|
+
|
171
|
+
<?php endif; ?>
|
172
|
+
|
173
|
+
<?php wp_reset_postdata(); ?>
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
<!-- 過去6ヶ月の記事をランダム表示 -->
|
178
|
+
|
179
|
+
<?php
|
180
|
+
|
181
|
+
$today = date('Y/m/d');
|
182
|
+
|
183
|
+
$setday = date('Y/m/d', strtotime('-6 month'));
|
184
|
+
|
185
|
+
$args = array(
|
186
|
+
|
187
|
+
'post_type' => 'post',
|
188
|
+
|
189
|
+
'post_status' => 'publish',
|
190
|
+
|
191
|
+
'category_name' => 'カテゴリ',
|
192
|
+
|
193
|
+
'date_query' => array(
|
194
|
+
|
195
|
+
array(
|
196
|
+
|
197
|
+
'compare' => 'BETWEEN',
|
198
|
+
|
199
|
+
'inclusive' => true,
|
200
|
+
|
201
|
+
'before' => $today,
|
202
|
+
|
203
|
+
'after' => $setday
|
204
|
+
|
205
|
+
),
|
206
|
+
|
207
|
+
),
|
208
|
+
|
209
|
+
'orderby' => 'rand',
|
210
|
+
|
211
|
+
'posts_per_page' => 6,
|
212
|
+
|
213
|
+
'post__not_in' => $post_ids //除外記事
|
214
|
+
|
215
|
+
);
|
216
|
+
|
217
|
+
$the_query = new WP_Query($args);
|
218
|
+
|
219
|
+
?>
|
220
|
+
|
221
|
+
<?php if($the_query->have_posts()): ?>
|
222
|
+
|
223
|
+
<?php while ($the_query->have_posts()): $the_query->the_post(); ?>
|
224
|
+
|
225
|
+
<!-- 投稿を表示 -->
|
226
|
+
|
227
|
+
<?php endwhile; ?>
|
228
|
+
|
229
|
+
<?php else: ?>
|
230
|
+
|
231
|
+
<!-- 投稿が無い場合 -->
|
232
|
+
|
233
|
+
<?php endif; ?>
|
234
|
+
|
235
|
+
<?php wp_reset_postdata(); ?>
|
236
|
+
|
237
|
+
```
|