rtec_event_meta
is a filter for the event_meta array before it’s returned by the function “rtec_event_meta”. It accepts an argument of the event_meta that has been created based on the event’s settings.
Usage
<?php add_filter( 'rtec_event_meta', 'function_name' ); ?>
Changelog
Pro
1.3 – introduced
Free
2.0 – introduced
Example: No Registration Limit for Logged-in Users
function ru_filter_event_meta( $event_meta ) {
if ( is_user_logged_in() ) {
$event_meta['limit_registrations'] = false;
}
return $event_meta;
}
add_filter( 'rtec_event_meta', 'ru_filter_event_meta' );
Example: Disable Registration for Events in a Category
function ru_disable_per_category( $event_meta ) {
if ( is_admin() ) {
return $event_meta;
}
$disabled_cat = 4; // Term ID for target category.
$tax = 'tribe_events_cat';
$terms = get_the_terms( $event_meta['post_id'], $tax );
if ( empty( $terms ) ) {
return $event_meta;
}
$ids = array();
foreach ( $terms as $term ) {
$ids[] = $term->term_id;
}
if ( in_array( $disabled_cat, $ids, true ) ) {
$event_meta['registrations_disabled'] = true;
return $event_meta;
}
return $event_meta;
}
add_filter( 'rtec_event_meta', 'ru_disable_per_category' );
Example: Logged-in users can only register for one event in a category
function ru_one_per_category( $event_meta ) {
if ( is_admin() ) {
return $event_meta;
}
if ( is_user_logged_in() ) {
$tax = 'tribe_events_cat';
$terms = get_the_terms( $event_meta['post_id'], $tax );
if ( empty( $terms ) ) {
return $event_meta;
}
$post_type = defined('Tribe__Events__Main::POSTTYPE') ? Tribe__Events__Main::POSTTYPE : 'tribe_events';
$args = array(
'post_type' => $post_type,
'post_status' => 'publish',
'posts_per_page' => 50,
'order' => 'ASC'
);
$ids = array();
foreach( $terms as $term ) {
$ids[] = $term->term_id;
}
$args['tax_query'] = array(
array(
'taxonomy' => $tax,
'field' => 'id',
'terms' => $ids
)
);
$posts = tribe_get_events( $args );
$event_ids = array();
foreach ( $posts as $post ) {
$event_ids[] = $post->ID;
}
$rtec = RTEC();
foreach ( $event_ids as $event_id ) {
$args = array(
'fields' => array( 'id' ),
'where' => array(
array( 'event_id', $event_id, '=', 'int' ),
array( 'user_id', get_current_user_id(), '=', 'int' )
),
'order_by' => 'registration_date'
);
$registrations = $rtec->db_frontend->retrieve_entries( $args, true );
if ( isset( $registrations[0] ) ) {
$event_meta['registrations_disabled'] = true;
}
}
}
return $event_meta;
}
add_filter( 'rtec_event_meta', 'ru_one_per_category' );