Skip to content
billerickson edited this page Sep 12, 2014 · 4 revisions

Using an alternative metabox

A very simple metabox is built in for controlling event start date and time. This can be replaced with your metabox tool of choice, whether that's CMB, ACF or something else.

Add this to your theme/core functionality plugin: add_filter( 'be_events_manager_metabox_override', '__return_true' );

In your metabox, use 'be_event_start' and 'be_event_end' as the start/end meta keys

Event Location

Install the Location Field extension. Add a location field to your metabox. Then use the following code in your theme:

<?php

$location = get_post_meta( get_the_ID(), 'be_event_location', true );
$location = explode( '|', $location );
echo '<p><img src="http://maps.googleapis.com/maps/api/staticmap?center=' . urlencode( $location[0] ). '&zoom=13&size=600x300&maptype=roadmap&sensor=false" /></p>';

Event Date

<?php
	$start = get_post_meta( get_the_ID(), 'be_event_start', true );
	$end = get_post_meta( get_the_ID(), 'be_event_end', true );
	
	// Only a start date
	if( empty( $end ) )
		$date = date( 'F j, Y', $start );
		
	// Same day
	elseif( date( 'F j', $start ) == date( 'F j', $end ) )
		$date = date( 'F j Y', $start );
	
	// Same Month
	elseif( date( 'F', $start ) == date( 'F', $end ) )
		$date = date( 'F j', $start ) . '-' . date( 'j, Y', $end );
		
	// Same Year
	elseif( date( 'Y', $start ) == date( 'Y', $end ) )
		$date = date( 'F j', $start ) . '-' . date( 'F j, Y', $end );
		
	// Any other dates
	else
		$date = date( 'F j, Y', $start ) . '-' . date( 'F j, Y', $end );

Event Time

<?php
	$start = get_post_meta( get_the_ID(), 'be_event_start', true );
	$end = get_post_meta( get_the_ID(), 'be_event_end', true );
	
	// Same date, same am/pm
	if( date( 'F j', $start ) == date( 'F j', $end ) && date( 'a', $start ) == date( 'a', $end ) )
		$time = date( 'g:i', $start ) . '&mdash;' . date( 'g:i a', $end );

	// Same date, different am/pm
	elseif( date( 'F j', $start ) == date( 'F j', $end ) )
		$time = date( 'g:i a', $start ) . '&mdash;' . date( 'g:i a', $end );

	// different date
	else
		$time = date( 'g:i a', $start ) . '&mdash;' . date( 'F j, g:i a', $end );
		
	echo '<p class="time">' . $time . '</p>';
Clone this wiki locally