#3521 closed enhancement (fixed)
meta_query parameter for template loops (bp_has_activities(), etc)
Reported by: | sboisvert | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 1.8 | Priority: | high |
Severity: | major | Version: | |
Component: | Activity | Keywords: | |
Cc: | sboisvert, eric.andrew.lewis@… |
Description
From what I've gathered from the support forums most methods of showing results that would be either based on an activity_meta or on a taxonomy would be to rewrite the query to pass the wanted ids in the $in for the 'bp_ajax_querystring' filter.
I was wondering if there was appetite to allow filtering of
$select_sql, $from_sql and $where_sql in BP_Activity_Activity::get(); which would allow to manipulate the query in such a way as to allow a much greater degree of flexibility, without having to basically do 2 sets of Queries (By this I refer to the first query that would pass the $in to the 'bp_ajax_querystring' filter for the real query)
(also let me know if I have created the patch correctly)
Attachments (2)
Change History (17)
#2
@
13 years ago
- Resolution set to fixed
- Status changed from new to closed
Thank you r-a-y, my apologies, you are indeed correct they do exactly what I need. It had not occurred to me that they would be all in one.
#3
@
13 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
r-a-y, I've gone thru this and found a slight problem. It may again be because I am not seeing the right way of doing it, and if so I thank you in advance for your insight.
While the one filter for all 3 does do the trick if one is only attempting to modify the query once, It quickly breaks down if you try to add a second component to the query.
Here is my use case:
First rewrite adds a join on activity_meta to filter only the activities that were posted in the language that the user has selected (or no filter)
Second rewrite joins on a term for a taxonomy (if on a tagged activity aggregation page).
Now I can always write this as one function, but I am currently building both these functions as partial rewrites of buddypress-multilingual and activity-stream-hashtag. Keeping them separate would make it easier to release the code and would allow other plugins the possibility to add to the query in a non destructive way. (Without having to go around doing some parsing and string replace of the original sql query.)
#4
follow-up:
↓ 8
@
13 years ago
I am wary of littering these classes with additional filters. They will all be deprecated when we move to custom post types. There more of them there are, and the more sophisticated the plugins that are built to take advantage of them, the more difficult the transition will be.
#5
@
13 years ago
- Resolution set to fixed
- Status changed from reopened to closed
That is a valid concern and as I mentioned for my use case I can bundle everything into one rewrite, it just makes the code less modular and less shareable, less future proof, but if that future is custom post types then I am fine with this problem being solved later on by a transition to custom post types.
#6
@
13 years ago
Thanks for your understanding, sboisvert. Don't let this stop you from asking for more filters and hooks elsewhere :)
#7
@
13 years ago
- Milestone changed from Awaiting Review to 1.5
Moving closed ticket out of Awaiting Review.
#8
in reply to:
↑ 4
;
follow-up:
↓ 9
@
12 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Replying to boonebgorges:
I am wary of littering these classes with additional filters.
Thoughts on building an activity_meta_query option into the API? I'm imagining something that's a replication of meta_query in WP_Query, but for BP activity.
$activity = bp_activity_get( array( array( 'key' => 'key_name', 'value' => 'value', 'compare' => '=' ) );
#9
in reply to:
↑ 8
@
12 years ago
- Keywords close removed
- Milestone changed from 1.5 to Future Release
Thoughts on building an activity_meta_query option into the API? I'm imagining something that's a replication of meta_query in WP_Query, but for BP activity.
I think it's a great idea. Patches welcome :)
#12
@
12 years ago
- Milestone changed from Future Release to 1.8
- Priority changed from normal to high
- Severity changed from minor to major
- Summary changed from Activity results that incorporate activity_meta and others to meta_query parameter for template loops (bp_has_activities(), etc)
I'm moving this to the 1.8 milestone, and expanding its scope to the Groups component as well, where we should be able to do something very similar. We'll test to see whether it's feasible for Members as well.
#14
@
12 years ago
- Owner set to boonebgorges
- Resolution set to fixed
- Status changed from reopened to closed
In 6950:
#15
@
12 years ago
Marking resolved. I think it's unwise to move forward with Members at the moment, because (a) it'll be harder to reconcile with the meta_value/meta_key params of WP_User_Query, and (b) it's likely to create confusion that it's possible to filter based on usermeta but *not* based on xprofile data. This is an area for future enhancement.
Thanks for your initial patch, ericlewis!
In the forthcoming BP 1.5, there are already filters lower down in the ::get() function:
http://buddypress.trac.wordpress.org/browser/trunk/bp-activity/bp-activity-classes.php#L152
http://buddypress.trac.wordpress.org/browser/trunk/bp-activity/bp-activity-classes.php#L157
I believe those filters should allow you to do what you want.