Support

Home Forums Event Espresso Premium EE4 – Post Object with Advanced Custom Fields to pull event time and date?

EE4 – Post Object with Advanced Custom Fields to pull event time and date?

Posted: October 15, 2014 at 4:08 pm

Viewing 3 reply threads


ty bonlando

October 15, 2014 at 4:08 pm

Hi!

I’m wanting to create a custom “featured event” callout on the main page, and i’ve sort of got it to work using advanced custom fields.

The problem is, i’d like to make it easier.

The callouts in question are under the slider here: https://www.jazzyyc.com/

Each element in the callout is generated on a page with it’s own custom fields. So a page_link field for the URL, a text field for the title, venue name, date and another page_link for the venue URL, and an image field for the image.

I’m able to select the event from a dropdown, publish and then it pulls the event title and link using this code below:

<?php

$post_object = get_field('post_object');

if( $post_object ): 

	// override $post
	$post = $post_object;
	setup_postdata( $post ); 

	?>
    <div>
    	<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    	<span>Post Object Custom Field: <?php the_field('field_name'); ?></span>
    </div>
    <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>

My question is, how can I pull the event date/time from the event page? I know that it is done with the upcoming events widget, so i’m hoping I can do it this way as well. Bonus points if I can pull the venue/venue link from the page as well, however I don’t think it’s that simple (I can create a post object for the venue).

Ideally, i’d like to select the event from the dropdown, and have the result look exactly how it is now on the front end. (or at the very least select the event and the venue).


Josh

  • Support Staff

October 20, 2014 at 1:08 pm

Hi Ty,

There’s an example of how to get the event’s datetimes from the EE_Event object in the developer documentation here:

http://developer.eventespresso.com/docs/ee-model-objects-and-custom-post-types/


ty bonlando

October 20, 2014 at 1:54 pm

Thanks Josh. I actually got the datetimes to work using the template tag :espresso_list_of_event_dates( $post->ID );

The problem I have was getting it to pull the venue from that event, using the template tag: espresso_venue_name(). None of the template tags for venue seemed to pull anything.

<?php
$event_post_A = get_field('event_post', 5792);
?>
<?php if( $event_post_A ): 
	// override $post
	$post = $event_post_A;
	setup_postdata( $event_post_A ); 

		?>

<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

<?php espresso_list_of_event_dates( $post->ID );?>
<?php espresso_venue_name( $post->ID );?> // DOESNT WORK
<?php wp_reset_query();
	   wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>

I’ll try looking at the documentation you’ve given me to see if I can find an answer. Thanks!


Josh

  • Support Staff

October 20, 2014 at 2:36 pm

Hi Ty,

The espresso_venue_name() template tag is intended to be used in a venue view. You can use the venue() method in an event view though. For more info on how to do that, please see Example #1 in the reply in this related thread from earlier today:
https://eventespresso.com/topic/getting-all-the-event-metas-like-locationapproved-registration-etc/#post-123804

Viewing 3 reply threads

The support post ‘EE4 – Post Object with Advanced Custom Fields to pull event time and date?’ 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.

Event Espresso