Skip to content

Instantly share code, notes, and snippets.

@Apina
Created December 15, 2014 07:58
Show Gist options
  • Save Apina/01b2066f217428fec182 to your computer and use it in GitHub Desktop.
Save Apina/01b2066f217428fec182 to your computer and use it in GitHub Desktop.
Associated Events plugin for EE4 - adds meta box to EE4 venues to make it easier to see which events have this venue attached.
<?php
/*
Plugin Name: Associated Events for EE4
Plugin URI:
Description: Adds an Associated Events meta baox to EE4 venues, which lists which events the venue has been attached to.
Version: 0.0.1
Author: Dean Robinson
Author URI:
*/
/*
IMPORTANT: Please note that this plugin is not endorsed or supported by Event Espresso. Please consider it as an example and use at your own risk.
If you prefer, the code below can be copied and added to a functions.php or site specific plugin, rather than as a standalone plugin.
*/
function myplugin_add_meta_box() {
add_meta_box( 'venue_list_events', __('Associated Events', 'event_espresso'), 'venue_list_events', 'espresso_venues', 'normal', 'default' );
}
add_action( 'add_meta_boxes', 'myplugin_add_meta_box' );
function venue_list_events() {
global $wpdb;
global $post;
$ventable = $wpdb->prefix . 'esp_event_venue';
$vid = $post->ID;
$results = $wpdb->get_results( "SELECT * FROM $ventable WHERE VNU_ID = $vid" );
$evs = array();
foreach ($results as $key) {
$evs[] = $key->EVT_ID;
}
$args = array(
'posts_per_page' => -1,
'orderby' => 'ID',
'order' => 'ASC',
'include' => $evs,
'post_type' => 'espresso_events',
'post_status' => 'publish',
'suppress_filters' => true
);
$posts_array = get_posts( $args );
foreach ($posts_array as $post) {
edit_post_link( $post->post_title, '<p>', '</p>', $post->ID );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment