SQL error when filtering by "My groups" in buddypress
-
Hi,
We’re getting errors when trying to get events belonging to groups that the current user is in when using the plugin with BuddyPress.
[Tue Jun 23 16:40:08 2015] [error] [client 127.0.0.1] WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘) ) AND (‘event_private’=0 OR (‘event_private’=1 AND (‘group_id’ IS NULL OR ‘gro’ at line 3 for query \r\n\t\t\tSELECT papv18ab2_em_events.post_id FROM papv18ab2_em_events\r\n\t\t\tLEFT JOIN papv18ab2_em_locations ON papv18ab2_em_locations.location_id=papv18ab2_em_events.location_id\r\n\t\t\t WHERE (‘recurrence’!=1 OR ‘recurrence’ IS NULL) AND ( event_start_date >= CAST(‘2015-06-23’ AS DATE) OR (event_end_date >= CAST(‘2015-06-23’ AS DATE) AND event_end_date != ‘0000-00-00’ AND event_end_date IS NOT NULL)) AND (‘event_status’=1) AND ( ‘group_id’ IN () ) AND (‘event_private’=0 OR (‘event_private’=1 AND (‘group_id’ IS NULL OR ‘group_id’ = 0)))\r\n\t\t\tGROUP BY papv18ab2_em_events.post_id ORDER BY event_start_date ASC, event_start_time ASC, event_name ASC\r\n\t\t\t \r\n\t\t made by require(‘C:\\work\\intranet-test\\wp-blog-header.php’), require_once(‘C:\\work\\intranet-test\\wp-includes\\template-loader.php’), include(‘C:\\work\\intranet-test\\wp-content\\themes\\inet_social\\page.php’), get_template_part, locate_template, load_template, require(‘C:\\work\\intranet-test\\wp-content\\themes\\inet_social\\content-page-bp.php’), the_content, apply_filters(‘the_content’), call_user_func_array, bp_replace_the_content, apply_filters(‘bp_replace_the_content’), call_user_func_array, BP_Members_Theme_Compat->single_dummy_content, bp_buffer_template_part, bp_get_template_part, bp_locate_template, load_template, require(‘C:\\work\\intranet-test\\wp-content\\themes\\inet_social\\buddypress\\members\\single\\home.php’), bp_get_template_part, bp_locate_template, load_template, require(‘C:\\work\\intranet-test\\wp-content\\themes\\inet_social\\buddypress\\members\\single\\groups.php’), bp_get_template_part, bp_locate_template, load_template, require(‘C:\\work\\intranet-test\\wp-content\\themes\\inet_social\\buddypress\\members\\single\\plugins.php’), do_action(‘bp_template_content’), call_user_func_array, bp_em_my_group_events_content, em_locate_template, include(‘C:\\work\\intranet-test\\wp-content\\themes\\inet_social\\plugins\\events-manager\\buddypress\\my-group-events.php’), em_events_admin, em_locate_template, include(‘C:\\work\\intranet-test\\wp-content\\themes\\inet_social\\plugins\\events-manager\\tables\\events.php’), EM_Events::get, referer: https://intranet/
I’ve dug in some and think I may have figured out the bug. The cause is in line 88 in bp-em-groups.php.
You’re evaluationg if there are any groups by doing a count on $groups, which is populated by groups_get_user_groups(). The problem is that at some point, groups_get_user_groups() started returning 2 elements: “groups” (an array containing the group IDs) and “total.”
Since the conditional on line 88 is:
if( count($groups) > 0 )And the $groups will always have 2 elements, that conditional is always true now, causing errors when no the user doesn’t actually belong to any groups.
Fix should be easy enough. Hope this helps.
The topic ‘SQL error when filtering by "My groups" in buddypress’ is closed to new replies.