Would anyone have any guidance on how to tackle a problem like this? Any advice at all would be greatly appreciated.
Thanks,
Ben
I am struggling with this one so any nudge in the right direction (however small) would be great.
I have tried going at it from the other direction but that seems like it will duplicate a lot of BuddyPress code and so doesn’t feel right. By this I mean, if I can’t query the BuddyPress activities based on the meta from the cpt the activities come from, I figured I could try querying the original CPT and filtering on the meta (easily done) and then outputting those as if they are activities. I’ve gotten quite far down that path by duplicating a lot of the code from activity\entry.php. But I’m missing a lot still calculating the date, adding comments, favoriting/reactions etc etc. It doesn’t feel right though and I’m sure I’ll miss things so that the two will never be the same and I’ll be stuck maintaining something that I prob should never have written.
One thought I had was that it might be possible to pull the cpt and find the associated activity id (like secondary_item_id in activity but in the other direction). I have not found a link between the two in that direction.
Then I thought, well if that link from cpt-to-activity is not available by default maybe I could grab it at the time of the initial creation of the activity and save it. Is that possible?
Apologies if this is starting to sound like a stream of consciousness. I’m complete lost right now.
Thanks for any help and support.
Regards,
Ben
Hi,
it’s not the solution but an example you can perhaps use.
The snippet handles the object members and sort them by type “contributing”
Replace object by activity and type by “beer” and see what you can do from that.
// add order options to members loop
function ch_member_order_options() {
?>
<option value="contributing"><?php _e( 'Contributing Members', 'buddypress' ); ?></option>
<?php
}
add_action( 'bp_members_directory_order_options', 'ch_member_order_options' );
// filter ajax members by contributing
function ch_filter_ajax_querystring( $querystring = '', $object = '' ) {
if( $object != 'members' )
return $querystring;
$defaults = array(
'type' => 'active',
'action' => 'active',
'scope' => 'all',
'page' => 1,
'user_id' => 0,
'search_terms' => '',
'exclude' => false,
);
$ch_querystring = wp_parse_args( $querystring, $defaults );
if( $ch_querystring['type'] == 'contributing' ) {
// grab members by Member Type role declared on xprofile
$users = get_users( array( 'fields' => array( 'ID' ), 'role' => 'contributor' ) );
$users_str = '';
foreach ( $users as $user ) {
$users_str .= $user->ID . ',';
}
$users_str = rtrim($users_str, ",");
$ch_querystring['include'] = $users_str;
$ch_querystring['type'] = 'alphabetical';
return $ch_querystring;
}
else
return $querystring;
}
add_filter( 'bp_ajax_querystring', 'ch_filter_ajax_querystring', 20, 2 );
https://buddypress.org/support/topic/adding-new-order-by-on-members-loop/
Members Loop
Member Types
Thanks, Dan,
I’ll dig in and try that out. There’s a lot here I don’t understand so may take some time. Thanks for the tip. I’ll let you know how I make out.
Regards,
Ben
Dan,
I spent some time on this and have figured out the loop that will give me the activity entries I need. I’m trying to add the list of activities on the same page I display the Beer custom post type. So show the beer info at the top and the list of related activities below it. I’m doing that on a theme page and would need to call the activity/entry.php for each of the entries. Is there a way to do that or would I need to copy the code from there?
The query will look something like this:
$args = array(
'post_type' => 'check_in',
'posts_per_page' => '-1',
'post_status' => array(
'publish',
),
'meta_key' => 'check_in_details_beer-id',
'meta_value' => $current_post
);
// run the query
$query_checkins = new WP_query ( $args );
// check the query returns posts
if ( $query_checkins->have_posts() ) :
while ( $query_checkins->have_posts() ) : $query_checkins->the_post();
$ci_postid = get_the_ID();
if ( bp_has_activities( bp_ajax_querystring( 'activity' ) . '&secondary_id='. $ci_postid ) ) :
Thanks for the help and support,
Ben