• Resolved vyabsley

    (@vyabsley)


    I think I may have asked this before, I’m not sure, but is there any simple enough way to create a venue map page that only puts pins on venues with events upcoming?

    A lot of the venues for events I am listing are one-offs who will likely not have any future events there – but I don’t want to have to delete these venues as it would be useful to keep them there for historical reasons.

    Cheers for any help!

    http://wordpress.org/extend/plugins/event-organiser/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Stephen Harris

    (@stephenharris)

    Mmm… not with the shortcode, but if you’re using it in a template file then its possible.

    You would just query for X number of upcoming events (via eo_get_events(), extract their venue’s ID (via eo_get_venue( $event_id ) ) and then display the venues map with eo_get_venue_map(), passing the collected venue IDs.

    Documentation for these functions can be found here: http://wp-event-organiser.com/documentation/function-reference/

    Of course its possible to create a shortcode which does the above if you really need that functionality as a shortcode.

    Thread Starter vyabsley

    (@vyabsley)

    Awesome, thank you!

    I’m still playing around with how to specify the map height, but I’ve learned so much more about WordPress by coding up this shortcode than I have from months of using it generally.

    Here’s what I came up with using your documentation:

    <?php
    function eo_upcoming_events_map() {
    $events = eo_get_events(array(
    	   'events_start_after'=>'today',
    	   'showpastevents'=>false,//Will be deprecated, but set it to true to play it safe.
      ));
    $venue_array;
    
    if($events):
       foreach ($events as $event):
    		$venue_id = eo_get_venue($event->ID);
    		$venue_array[] = $venue_id;
       endforeach;
    endif;
    
    echo eo_get_venue_map($venue_array);
    }
    
    add_shortcode('eo_upcoming_events_map','eo_upcoming_events_map');
    ?>

    Thread Starter vyabsley

    (@vyabsley)

    Sorry for the double-post, but I was able to get the height thing working. I don’t really need the other attributes (e.g. width, venue array, etc) working yet, so I’ll leave it for now – but here’s the code (mostly replicating the proper in-built map shortcode) in case it’s of use to anyone else.

    <?php
    function eo_upcoming_events_map($args=array()) {
    $args_array = array('zoom' => 15, 'scrollwheel'=>true, 'zoomcontrol'=>true, 'rotatecontrol'=>true,
    			'pancontrol'=>true, 'overviewmapcontrol'=>true, 'streetviewcontrol'=>true,
    			'maptypecontrol'=>true, 'draggable'=>true,'maptypeid' => 'ROADMAP',
    			'width' => '100%','height' => '200px','class' => '',
    			'tooltip'=>false
    			);
    $args = shortcode_atts($args_array , $args );
    		//Cast zoom as integer
    		$args['zoom'] = (int) $args['zoom']; 
    
    		//Escape attributes
    		$width = esc_attr($args['width']);
    		$height = esc_attr($args['height']);
    		$class = esc_attr($args['class']);
    		 //If class is selected use that style, otherwise use specified height and width
    		if( !empty($class) ){
    			$class .= " eo-venue-map googlemap";
    			$style = "";
    		}else{
    			$class = "eo-venue-map googlemap";
    			$style = "style='height:".$height.";width:".$width.";' ";
    		}
    
    $events = eo_get_events(array(
    	   'events_start_after'=>'today',
    	   'showpastevents'=>false,//Will be deprecated, but set it to true to play it safe.
      ));
    
    $venue_array;
    
    if($events):
       foreach ($events as $event):
    		$venue_id = eo_get_venue($event->ID);
    		$venue_array[] = $venue_id;
       endforeach;
    endif;
    
    echo eo_get_venue_map($venue_array, array('height'=>$height));
    }
    
    add_shortcode('eo_upcoming_events_map','eo_upcoming_events_map');
    ?>

    So now I can use [eo_upcoming_events_map height=”600px”] on a page to display only venues with upcoming events.

    Plugin Author Stephen Harris

    (@stephenharris)

    Awesome, nice work 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Force map to display only venues with upcoming events’ is closed to new replies.