I have a custom post type called "Events". The post displays fine, except that the WP Query loop only displays one post instead of all of them. Here is the complete code from my functions.php file for Events:
function min_get_events ( $echo = true ) {
$events = new WP_query(array(
'post_type' => 'events',
'posts_per_page' => -1,
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => 'min_event-start',
'meta_query' => array(
'key' => 'min_event-start',
'value' => date('Y-m-d'),
'compare' => '>',
)
));
$i = 0;
$n = 1;
if ( $events->have_posts() ) :
while ( $events->have_posts() ):
global $post;
$events->the_post();
$open_date = get_post_meta($post->ID, 'min_event-start', true);
$close_date = get_post_meta($post->ID, 'min_event-end', true);
$start = strtotime($open_date);
$end = strtotime($close_date);
if ($start==$end || $start > $end) {
$date_string = date('F j, Y', $start);
}
else {
$date_string = date('F j, Y', $start) .' – '. date('F j, Y', $end);
}
//$description = get_post_meta($post->ID, 'event-description', true);
$location = get_post_meta($post->ID, 'min_event-location', true);
$url = get_post_meta($post->ID, 'min_event-url', true);
//$registration_url = get_post_meta($post->ID, 'event-registration-url', true);
$cta_text = get_post_meta($post->ID, 'min_event-cta-text', true);
$cta = !empty($cta_text) ? $cta_text : 'Register Now';
$i++;
if ( $i == 1 ) {
?>
<div class="row">
<?php
}
?>
<div class="event col-sm-4">
<a href="<?= $url ?>">
<?php the_post_thumbnail('thumb-events'); ?>
</a>
<h1><?= htmlentities($post->post_title) ?></h1>
<div >
<div><?= $date_string; ?></div>
<div><?= htmlentities($location) ?></div>
<div><a href="<?=$url;?>" class="register-now"><?= $cta; ?></a></div>
</div>
<!-- <p><?= $description ?></p> -->
<!-- <p><a href="<?=$url;?>" class="register-now"><?= $cta; ?></a></p> -->
</div> <!-- .event -->
<?php
if ( $i == 3 || ($events->current_post +1) == $events->post_count) {
?>
</div> <!-- <?php echo $i; ?> .row <?php echo $n; ?> -->
<?php
$i = 0;
$n++;
}
endwhile;
endif;
ob_start();
?>
<?php
$return = ob_get_contents();
ob_end_clean();
wp_reset_postdata();
if ( $echo ) {
echo $return;
} else {
return $return;
}
}
Am I missing something here?
posts_per_page
param to 4? The purpose is to determine if that param is affecting your query at all. Apre_get_posts
hook somewhere might be limiting your result as well?