Database error with meta queries using tribe_events_views_v2_view_repository_arg
-
Hello,
This may be outside the scope of this forum, but I appreciate any help you can provide.
We’ve got a membership website using Learndash groups, and we are limiting what events are shown in TEC views based on which group the user is in. We’re doing this using meta queries inside the tribe_events_views_v2_view_repository_args filter.
The following code produces a database error. I’m not sure if maybe it’s looking in the wrong database table for the “public_event” meta key. However, if we remove the meta_query for the “public_event” key, or alternatively remove the foreach loop, it works just fine. We just can’t have them together.
// Start Group Visibility Restriction add_filter( 'tribe_events_views_v2_view_repository_args', 'tec_exclude_events_group', 10, 3 ); function tec_exclude_events_group( $args, $context, $view ) { $args = group_limiter($args); return $args; } function group_limiter($args) { $userid = get_current_user_id(); $lms_user_group = learndash_get_users_group_ids($userid); $i = 0; $args['meta_query'][$i] = array( 'key' => 'public_event', 'value' => '1', ); $i++; foreach ($lms_user_group as $groupID) { $args['meta_query'][$i] = array( 'key' => '_ld_groups_membership_group_'.$groupID, 'compare' => 'EXISTS', ); $i++; }; if($i > 1): $args['meta_query']['relation'] = "OR"; endif; return $args; }
WordPress database error: [Unknown column 'wp_tec_occurrences.meta_key' in 'where clause']
SELECT wp_posts.ID, CAST( wp_tec_occurrences.start_date AS DATETIME ) AS event_date, CAST( wp_tec_occurrences.duration AS DECIMAL ) AS event_duration FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) JOIN wp_tec_occurrences ON wp_posts.ID = wp_tec_occurrences.post_id WHERE 1=1 AND ( CAST(wp_tec_occurrences.end_date_utc AS DATETIME) > '2023-04-11 22:44:48' OR ( wp_tec_occurrences.meta_key = 'public_event' AND wp_tec_occurrences.meta_value = '1' ) OR wp_postmeta.meta_key = '_ld_groups_membership_group_1409' ) AND wp_posts.post_type = 'tribe_events' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')) GROUP BY wp_tec_occurrences.occurrence_id ORDER BY wp_tec_occurrences.start_date ASC, wp_tec_occurrences.duration ASC, wp_posts.post_date ASC LIMIT 0, 11I appreciate any insight you could give me on this.
Thank you,
Corey
- The topic ‘Database error with meta queries using tribe_events_views_v2_view_repository_arg’ is closed to new replies.