#6629 closed enhancement (wontfix)
Accept array for the parameter item_id for bp_activity_add() function
Reported by: | Tafmakura | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Core | Keywords: | |
Cc: |
Description
For a project I am working on I want my custom activity to have dynamic content of the post that invokes the activity when it is created instead of the static data that is passed to the activity's 'content' parameter, I achieved this by passing the post id as the secondary_item_id when the activity is created and then creating a custom entry.php template that displays activity content based on the secondary item_id (i.e featured image and exerpt) this works well. The problem is i now have activities that are suppose to show multiple posts in the activity content (don't ask how or why). Using the method above I can simply save the post id's into the secondary_item_id parameter as an array or comma separated string and then later display them by executing a loop.
The problem is that bp_activity_add() only accepts numbers(no spaces or letters ) and it will not accept an array either. I am no PHP developer but can secondary_item_id not accept an array or comma string or perhaps should there not be another parameter where this can be stored. i ended up using the content parameter to store a comma separated list of post IDs. It is untidy because by default the activity function will display this info yet I want it hidden.
Change History (4)
#1
@
9 years ago
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
#2
@
9 years ago
Thanks boone It worked so well it brought tears to my eyes hahaha. I ended up storing the ids as a array I hope that has no disadvantages when calling the data later, I felt it would be more efficient.
#3
@
9 years ago
Glad to hear it worked!
Storing as an array is fine. The only potential limitation is if you later want to make the following query: "show me all activity items associated with WP post 123" (like I showed in my 'meta_query' example). This won't work if each post doesn't have its own row in the activitymeta table.
Hi Tafmakura - Thanks for the ticket request.
The reason why
item_id
andsecondary_item_id
accept only integers is that thewp_bp_activity
database table only accepts integer values in this column. This fact about the database schema is part of what allows the activity component to scale as well as it does. So I'm afraid that it's not something we can change directly.For your purposes, I'd consider using activity metadata instead of
secondary_item_id
. It'd look something like this:If you ever need to query activity items that match a specific post ID, use
'meta_query'
:This way you can do it without resorting to ugly stuff like comma-separated lists :)