Home › Forums › Calendar Products › Events Calendar PRO › PHP Warning: Invalid argument supplied for foreach()
- This topic has 6 replies, 3 voices, and was last updated 10 years, 7 months ago by
Support Droid.
-
AuthorPosts
-
September 9, 2015 at 9:59 am #1003364
Gargi
ParticipantTwo sections of our site are giving us this error.
http://canphi.ca/our-courses/
http://canphi.ca/our-events/I’ve googled. I’ve read the forums. I’ve deactivated all the plugins. I CANT figure this out.
Here’s a snippet of some of our template code that’s giving the error.
<ul class=”block-grid-4 events-list”>
<?php foreach($events as $post): setup_postdata( $post ); ?>
<li id=”event-<?php the_ID();?>” <?php post_class();?>>
“>
<div class=”event-thumbnail text-center”>
<?php the_post_thumbnail( ‘event-thumb’ ); ?>
</div><h4><?php the_title();?></h4>
<p class=”event-time”>
<?php if(tribe_event_is_multiday()): ?><span class=”date-start dtstart”>
<?php
$start_year = tribe_get_start_date( get_the_ID(), true, ‘Y’ );
$end_year = tribe_get_end_date( get_the_ID(), true, ‘Y’ );$start_month = tribe_get_start_date( get_the_ID(), true, ‘F’ );
$end_month = tribe_get_end_date( get_the_ID(), true, ‘F’ );if($start_year === $end_year){
echo tribe_get_start_date( get_the_ID(), true, ‘F j’ );
echo ” – “;
if($start_month === $end_month){
echo tribe_get_end_date( get_the_ID(), true, ‘j, Y’ );
}else{
echo tribe_get_end_date( get_the_ID(), true, ‘F j, Y’ );
}
}else{
echo tribe_get_start_date( get_the_ID(), true, ‘F j, Y’ );
echo ” – “;
echo tribe_get_end_date( get_the_ID(), true, ‘F j, Y’ );
}?>
</span><?php else: ?>
<?php echo tribe_events_event_schedule_details( $event_id); ?>
<?php endif; ?></p>
<?php if(tribe_get_city() && tribe_get_region()):?>
<p class=”event-location”><?php echo tribe_get_city() . ‘, ‘ . tribe_get_region(); ?></p>
<?php endif; ?>
<?php endforeach; wp_reset_postdata(); ?>
September 9, 2015 at 2:43 pm #1003507Brian
MemberHi,
Sorry for the issues you are having. I can try to help out, but I am limited in supporting custom coding.
It looks like the $event variable is empty or not an array so the foreach cannot work with it.
How are you creating that variable?
Since this is custom coding is there a source you used to create it or an example?
Let me know and we can go from here.
Thanks
September 9, 2015 at 3:11 pm #1003515Gargi
ParticipantI think this is what you mean…. this is a little higher up the page calling in the functions
<?php
$arg = array(
‘post_type’ => ‘tribe_events’,
‘orderby’ => ‘event_date’,
‘order’ => ‘ASC’,
‘tribe_events_cat’ => ‘events’
);
$events = ‘TribeEventsQuery’;if($events):
?>September 9, 2015 at 4:56 pm #1003545Brian
MemberSo this is ($events = ‘TribeEventsQuery’;) setting the variable events to equal TribeEventsQuery so I would delete that.
I would review using tribe_get_events to help get this resolved:
Something like this would work to get 10 future events:
$events = tribe_get_events( array(
'posts_per_page' => 10,
'start_date' => new DateTime()
) );
Cheers
September 9, 2015 at 5:10 pm #1003549Gargi
Participantthank you!!
September 10, 2015 at 8:06 am #1003689Brian
MemberYou’re Welcome.
September 25, 2015 at 7:05 am #1008660Support Droid
KeymasterThis topic has not been active for quite some time and will now be closed.
If you still need assistance please simply open a new topic (linking to this one if necessary)
and one of the team will be only too happy to help. -
AuthorPosts
- The topic ‘PHP Warning: Invalid argument supplied for foreach()’ is closed to new replies.
