Hello again Kevin,
This ended up being more complex than I thought but I have something that should work!
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' );
If you can follow the code works by getting the event categories that the event in question has. Then getting all events that have that same category. The IDs of these events are collected. Then finally the registration database is searched to see if there are any entries that match the user that is logged in. Registration is disabled if one is found.
Let me know if you have questions!
– Craig