I have a category, called events. It is assigned to one post. So I created the following loop:
$args = array ('category_name' => 'events', 'posts_per_page' => 4, 'order_by' => 'date', 'order' => 'DESC' );
$category_posts = new WP_Query($args);
if ($category_posts->have_posts()) {
while ($category_posts->have_posts()) {
$category_posts->the_post();
var_dump($category_posts->the_post());
?>
<div class="col-md-6">
<?php $category_posts->the_post_thumbnail(array('class' => 'events-image')); ?>
</div>
<div class="col-md-6">
<h4><?php echo $category_posts->the_title(); ?></h4>
<span class="date"><?php echo date('M j, Y', $category_posts->get_the_date()); ?></span>
<p><?php echo implode(' ', array_slice(str_word_count($category_posts->the_content(), 2), 0,120)); ?> [...]</p>
</div>
<?php
}
}
Notice the var_dump($category_posts->the_post());
it comes into here and does this var_dump
but the Output is NULL
. wtf?
Whats confusing is it has posts, its get into the while statement but the $category_posts->the_post()
is null? This makes little to no sense at all.
Aucun commentaire:
Enregistrer un commentaire