Venue Column in the Events Admin List
Adds a Venue column to Events in the dashboard, so you can see where each event takes place without opening it.
Opens WPIDE on
Code
add_filter( 'manage_tribe_events_posts_columns', function ( $columns ) {
$columns['wpide_venue'] = __( 'Venue' );
return $columns;
}, 20 );
add_action( 'manage_tribe_events_posts_custom_column', function ( $column, $post_id ) {
if ( 'wpide_venue' !== $column ) {
return;
}
$venue_id = (int) get_post_meta( $post_id, '_EventVenueID', true );
if ( ! $venue_id ) {
echo '—';
return;
}
static $primed = false;
if ( ! $primed ) {
global $wp_query;
$ids = array();
foreach ( (array) $wp_query->posts as $p ) {
$ids[] = (int) get_post_meta( is_object( $p ) ? $p->ID : (int) $p, '_EventVenueID', true );
}
_prime_post_caches( array_filter( array_unique( $ids ) ), false, false );
$primed = true;
}
$venue = get_post( $venue_id );
$city = get_post_meta( $venue_id, '_VenueCity', true );
if ( $venue ) {
printf( '<a href="%1$s">%2$s</a>%3$s', esc_url( (string) get_edit_post_link( $venue_id ) ), esc_html( $venue->post_title ), $city ? '<br><small>' . esc_html( $city ) . '</small>' : '' );
}
}, 10, 2 );
Notes
Venue names are loaded in one query for the whole page.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.