[buddypress-trac] [BuddyPress Trac] #6629: Accept array for the parameter item_id for bp_activity_add() function
buddypress-trac
noreply at wordpress.org
Sun Sep 20 22:26:17 UTC 2015
#6629: Accept array for the parameter item_id for bp_activity_add() function
-------------------------+----------------------
Reporter: Tafmakura | Owner:
Type: enhancement | Status: closed
Priority: normal | Milestone:
Component: API | Version:
Severity: normal | Resolution: wontfix
Keywords: |
-------------------------+----------------------
Changes (by boonebgorges):
* status: new => closed
* resolution: => wontfix
* milestone: Awaiting Review =>
Comment:
Hi Tafmakura - Thanks for the ticket request.
The reason why `item_id` and `secondary_item_id` accept only integers is
that the `wp_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:
{{{
// When creating the activity item:
$activity_id = bp_activity_add( $args );
bp_activity_add_meta( $activity_id, 'wp_post_id', $post_1 );
bp_activity_add_meta( $activity_id, 'wp_post_id', $post_2 );
// etc
// Then, when rendering the dynamic content:
$wp_post_ids = bp_activity_get_meta( $activity_id, 'wp_post_id', false );
foreach ( $wp_post_ids as $wp_post_id ) {
// get the content of $wp_post_id
}
}}}
If you ever need to query activity items that match a specific post ID,
use `'meta_query'`:
{{{
$activities = bp_activity_get( array(
// ...
'meta_query' => array(
array(
'key' => 'wp_post_id',
'value' => $wp_post_id,
),
),
// ...
) );
}}}
This way you can do it without resorting to ugly stuff like comma-
separated lists :)
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/6629#comment:1>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac
More information about the buddypress-trac
mailing list