Support » Plugin: All-in-One Event Calendar » How do I use the event start/end time fields in my functions file?

  • Resolved chrislondon

    (@chrislondon)


    Hi there. I’m trying to write a function to add Google event meta data to the <head> of each event page on my site. I’m doing this so my events get displayed on my Google business listing.

    This is probably basic – my PHP isn’t great – but I’m struggling to get the value from the ai1ec ‘start’ and ‘end’ fields to use in the function in my functions.php file.

    To make it simple, in this example I’m just trying to insert the value from the ‘start time’ field into a paragraph at the top of my event page, before the loop (I’m using the Genesis framework). I know there are easier ways of using ai1ec fields in the main body of the page – I’m just writing it like this for simplicity’s sake. (In the finished function, I’ll be using this value in the <head>, not the main body of the page.)

    I thought it should be something like this…

    function google_event_meta () {
    	// this line is wrong
    	$start_time = get_post_field( 'start' );
    
    	if ( is_singular( 'ai1ec_event' ) ) {
    	echo '<p>' . $start_time . '</p>';
    	}
    }
    add_action( 'genesis_before_loop', 'google_event_meta' );

    I guess I’ve misunderstood how to get field values from ai1ec. Can anyone tell me how to do it? Or is there a better way to inject code that includes values like start and end time into the <head> of the document?

    Any advice appreciated!

    • This topic was modified 1 year, 2 months ago by chrislondon.
    • This topic was modified 1 year, 2 months ago by chrislondon.
    • This topic was modified 1 year, 2 months ago by chrislondon.
Viewing 1 replies (of 1 total)
  • I think I’ve figured this out. I’m waiting to see if my events correctly feed through to my Google business listing.

    I’m not sure my solution is the best way of doing it but, if it works, I’ll post the code in case it’s helpful to others.

Viewing 1 replies (of 1 total)
  • The topic ‘How do I use the event start/end time fields in my functions file?’ is closed to new replies.