[buddypress-trac] [BuddyPress] #5119: Group Meta Query - allow more than one meta_key
buddypress-trac
noreply at wordpress.org
Fri Jul 26 22:04:00 UTC 2013
#5119: Group Meta Query - allow more than one meta_key
-------------------------+-----------------------------------
Reporter: imath | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Groups | Version: 1.8
Severity: normal | Keywords: has-patch 2nd-opinion
-------------------------+-----------------------------------
"Bonsoir" !
Since last ticket, i've been exploring this new powerful feature for
groups loop : the groups meta query. First i'd like to say it's a really
great feature that would help me so much for a current project if it could
play with more than one meta_key at a time.
Let's consider this groups loop argument :
{{{
$group_args = array(
'type' => 'active',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_grooks_featured',
'value' => 1,
'type' => 'numeric',
'compare' => '='
),
array(
'key' => '_grooks_profile',
'value' => 's:4:"arts"',
'compare' => 'LIKE'
),
array(
'key' => '_grooks_group',
'value' => 1,
'type' => 'numeric',
'compare' => '='
)
)
);
}}}
if i run the loop, the result is a sql error such as "unknown column
mt1.group_id" or "unknown column mt2.group_id, even if the data are set in
bp_groups_groupmeta.
So i dived into BP_Groups_Group::get() and mostly
BP_Groups_Group::get_meta_query_sql(). In this last function, i think
(unless the goal is to only allow one meta_key query) that it should use
preg_match_all on {{{$meta_sql['join']}}} to get all the table alias, it
should get all the where clauses. The relation "OR" also needs to use
DISTINCT, and i had to modify the $total_groups_sql to avoid another sql
error after my edits.
Sorry for the last part if i explained badly :(
So i suggest the diff attached to this ticket as it seems to work on my
config.
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/5119>
BuddyPress <http://buddypress.org/>
BuddyPress
More information about the buddypress-trac
mailing list