Support

Home Forums Event Espresso Premium PHP Snippet for listing out event archive?

PHP Snippet for listing out event archive?

Posted: June 19, 2014 at 5:42 pm


louisianapipeliners

June 19, 2014 at 5:42 pm

Hi guys, Is there some php code that I can use to list out an archive of all past events?


Dean

June 20, 2014 at 1:48 am

Hi,

Something like this could be used – https://gist.github.com/joshfeck/e3c9540cd4ccc734e755

You would need to change show_expired to true.

You would probably want to not show future events. There isn’t a setting for this, but it can be done with the wp_query itself, some thing like this_

					<ul class="events">
					<?php			
					$atts = array(
						'title' => NULL,
						'limit' => 100,
						'css_class' => NULL,
						'show_expired' => TRUE,
						'month' => NULL,
						'category_slug' => NULL,
						'order_by' => 'start_date',
						'sort' => 'DESC'
					);
					// run the query
					global $wp_query;
					$wp_query = new EE_Event_List_Query( $atts );
						if (have_posts()) : while (have_posts()) : the_post();

							$post = get_post( get_the_ID() );
							$current_date = current_time( 'timestamp' );
							$event_date = strtotime($post->DTT_EVT_start);

							if( $event_date > $current_date ) { continue; }
							//var_dump($post);
					        ?>
					        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>    	
					<?php
						endwhile;
						else:
					?>
						<li>No Upcoming Events</li>
					<?php 
					    endif;
					// now reset the query and postdata
					wp_reset_query();
					wp_reset_postdata();
					?>
					    </ul>

Note that this is purely an example, you may need to tweak it to make it work for your individual use case.


louisianapipeliners

June 20, 2014 at 3:42 pm

Thanks so much. I have a similar question. My client would like to show upcoming events for a particular category in the sidebar. And this would change from page to page. If they go to the wordpress page “Dinners”, the sidebar should list all upcoming events under the dinners category. If the user goes to the “Meetings” page, the sidebar should list all upcoming events under the meetings category. Is there some php code that I can use to just list the upcoming events for a particular category?

Thanks again for all the help.


louisianapipeliners

June 21, 2014 at 11:49 am

Ill actually use what you’ve provided, thanks so much.


louisianapipeliners

June 21, 2014 at 12:44 pm

Is there a reason I can’t access the venue, desc and short_desc within $post?

Example:
This works fine: $eventDate = $post->DTT_EVT_start;

But what if I want to display [_EVT_desc:protected] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce tincidunt bibendum ligula nec auctor. Morbi vitae neque varius, rutrum tellus in.

Also, all I can find for “Venue” within the $post dump is [_Venue:protected]=>.

If i can get the Venue and Event desc within this sidebar I will be good to go.


louisianapipeliners

June 21, 2014 at 1:14 pm

I see that I can you post_excerpt for a short description. That will work. Just let me know if there’s any way I can get the venue in there.

Thanks.


Dean

June 23, 2014 at 4:16 am

Hi,

But what if I want to display [_EVT_desc:protected] =>

I assume you are trying to display the Event description? If so use:

<?php the_content(); ?>

Doing a var_dump/print_r on $post will reveal a lot of data as well.

I will have to get back to you on the venue aspect.


Brent Christensen

  • Support Staff

June 24, 2014 at 4:20 pm

Hi Eddie,

I’m Event Espresso’s lead dev.

We’ve integrated the Kint debugging tool into Event Espresso, so anywhere you want to get a better look at an object (or array, or string, or whatever), you can simply add something like:

	global $post;
	d( $post );

into your code, and it will output all kinds of wondrous information.

So if you were to add the above anywhere inside the “loop”, and take a look at one of the EE Event post objects, you will see that we have attached all of the event data to the WP post object, but we have ALSO attached our EE_Event Custom Post Type (CPT) object to it as well.

to get a better look at the EE CPT object, you could change the above to this:

	global $post;
	d( $post->EE_Event );

Notice that in the Kint output (click the + sign to expand the container) there is a tab named “Available Methods” (http://awesomescreenshot.com/00931ch406) ?
click on that to see a list of every function you can call directly on the EE_Event CPT object (its a big list).

One of those methods is “venues()” (http://awesomescreenshot.com/04c31chd29)

so calling:

	global $post;
	$venues = $post->EE_Event->venues();

will give you an array of any related venues that belong to the event.

Now run d( $venues ); to see everything you can do with Venues (you’ll have to dig into that array of course).

Keep in mind that it’s always a wise idea to test the object you have before attempting to run methods on it, so do something like this first:

	global $post;
	if ( $post->EE_Event instanceof EE_Event ) {
		$venues = $post->EE_Event->venues();
		d( $venues );
	}

That should keep you out of trouble for a while!

The support post ‘PHP Snippet for listing out event archive?’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  Brent Christensen 5 years, 2 months ago ago

Topic Tags

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!