Try globalizing $post
inside of event-item.php
.
Also: be sure to call wp_reset_postdata()
after you close your $loop
while loop.
e.g.:
<!-- event-item.php -->
<?php
// globalize $post
global $post;
?>
<div id="event-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="event-date"><?php echo $event_date; ?></div>
<div class="event_time"><?php echo $event_time; ?></div>
<div class="event-speaker"><?php echo $event_speaker; ?></div>
<div class="event-title"><a href="https://wordpress.stackexchange.com/questions/49285/<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
<div class="event-description-excerpt"><?php the_excerpt(); ?></div>
</div>
<!-- event-item.php -->
and then:
<?php
endwhile;
// Restore $post global to the primary query
wp_reset_postdata();
?>
Edit
Assuming the problem is just the post meta data, I would suggest moving the post meta data variables inside loop-item.php
. Only a guess, but perhaps your local variables aren’t getting passed through the include()
function that is part of get_template_part()
.
So, like this:
<!-- event-item.php -->
<?php
// Define these here, inside loop-item.php
$wr_event_fields = get_post_custom();
$event_date_timestamp = $wr_event_fields['_wr_event_date'][0];
$event_date = strftime('%d.%m.%Y', $event_date_timestamp);
$event_time = $wr_event_fields['_wr_event_time'][0];
$event_speaker = $wr_event_fields['_wr_event_speaker'][0];
?>
<div id="event-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="event-date"><?php echo $event_date; ?></div>
<div class="event_time"><?php echo $event_time; ?></div>
<div class="event-speaker"><?php echo $event_speaker; ?></div>
<div class="event-title"><a href="https://wordpress.stackexchange.com/questions/49285/<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
<div class="event-description-excerpt"><?php the_excerpt(); ?></div>
</div>
<!-- event-item.php -->
Also, to avoid undefined variable
notices, you should define your variables using isset()
conditionals; e.g. change this:
$event_date_timestamp = $wr_event_fields['_wr_event_date'][0];
…to this:
$event_date_timestamp = ( isset( $wr_event_fields['_wr_event_date'][0] ) ? $wr_event_fields['_wr_event_date'][0] : false );