Forum Replies Created
-
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,
BenThanks, 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,
BenI 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,
BenWould anyone have any guidance on how to tackle a problem like this? Any advice at all would be greatly appreciated.
Thanks,
BenThanks, David,
This is exactly what I needed.
Regards,
BenSure. I finally got back to this and spent some time debugging it. I had assumed that the meta box fields would be available but in retrospect that was not a good assumption (why would they, right?). Once I figured that out I just wrote some code to retrieve the fields I needed. If you use $activity->secondary_item_id you can pull in the data you need from the original meta box fields.
The final code from my tests is below.
I hope this helps. And, thanks to Shane for putting me on the right path.
function ben_filter_activity_body( $content, $activity ) { $checkintext = ""; if ( 'new_check_in' === $activity->type ) { if ( isset( $activity->secondary_item_id ) ) { $current_post = $activity->secondary_item_id; $beerName = get_post_meta($current_post, 'check_in_details_beer-name', true); $barName = get_post_meta($current_post, 'check_in_details_bar-name', true); $beerRating = get_post_meta($current_post, 'check_in_details_rating', true); $beerReview = get_post_meta($current_post, 'check_in_details_notes', true); $checkintext = "Drank: " . $beerName . " At: " . $barName . "<br />Rated it: " . $beerRating . "<br />Review: " . $beerReview; } $content = 'Note: (ID:'. $activity->secondary_item_id . ')' . $content . $checkintext; } return $content; } add_filter( 'bp_get_activity_content_body', 'ben_filter_activity_body', 25, 2 );
I’m working on other parts of the app for now but still need to solve the problem of how to get a lot more detail into the stream. Has anyone done that before?
Any help or pointers on how to pull info out of custom meta box fields and insert that into the activity stream would be greatly appreciated.
Thanks,
BenHi Shane,
This did not take me much time at all. I was able to define the CPT in a plugin and everything works as expected.
The one thing I’m not sure how to fix though is getting more detail out of my CPT. I have some meta box fields defined that contain info I’d like to show in the activity stream. I’m not seeing those in the var_dump so I’m not sure how I would extract those.
Would you have an idea about that?
Thanks,
BenActually the BP component idea might be a good one for me also. I spent some time trying to find the source for the Site Tracking component as I thought I might be able to learn a lot from that but I was never able to find it. Would you know where I would look for that?
Thanks,
BenYup. Thanks. I already had my CPT working in BP using the methods described in that codex page. It was posting to the Activity stream. What was not working was having the ability to customize what information showed up in the stream. I think some of that was due to my using Pods to dynamically generate the CPTs (and of course some of it could be due to my lack of knowledge).
At any rate, I had hit some limits in Pods anyway so it’s time to learn how to manually code those. It doesn’t look too complicated (famous last words :)) so I think it should just take me a couple of days.
Thanks again,
BenPods = http://pods.io/
Pods has been useful to help me prototype and prove that I can build what I want to build but probably won’t scale to where I need it so I think I’ll look to pull that and build the CPTs in a more traditional way. Let me do that and then come back to this once I have it working again.
Thanks for the help and support.
Thanks, Shane,
This is helpful. It does seem to work for all types except my CPTs. 🙁 For my Check In CPT it does not appear to fire at all (i.e. I’m not seeing the var_dump or the ‘start of content’ message).
One thing I should have mentioned is that I am using the Pods plugin to define my CPTs. So that is probably why the filter does not called, I guess. Would you have any idea why that might be? Any suggestions for what I might try to get around that?
Thanks for the help and support,
Benok I figured this out. And I was in fact missing something pretty fundamental. I was copying from the \bp-themes\bp-default\ folder instead of from \bp-templates\bp-legacy\buddypress. Once I fixed that it all came together.
Can someone explain the difference between the two folders. FWIW, the bp-legacy name was throwing me off. The word legacy to me hinted at something that was deprecated so I had assumed I should stay away from there.
The support topic https://buddypress.org/support/topic/how-to-create-template/ set me straight.
Thanks,
BenI poked around and re-read the codex and watched the BuddyCamp Brighton video with Hugo Ashmore (the video was really good btw).
Unfortunately I am still stuck. I suspect I’m missing some little but fundamental thing but can’t figure out what that is.
My child theme folder only includes three files:
twentyfourteen-child\buddypress\members\single\home.php
twentyfourteen-child\functions.php
twentyfourteen-child\style.csshome.php is an exact duplicate of the file at plugins\bp-themes\bp-default\members\single\home.php
styles.css is empty (except for comments) and functions.php only contains:
add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’ );
function theme_enqueue_styles() {
wp_enqueue_style( ‘parent-style’, get_template_directory_uri() . ‘/style.css’ );
}I’m baffled. Anyone have an idea for me to try or some additional how-to docs on how to properly setup a child them for both wp and bp?
Thanks,
BenThanks for the quick response, shane.
I think I may need some more remedial help though as in trying to do that I broke the page.
I am using the twentyfourteen theme as a base so have created a child of that called twentyfourteen-child.
To override the home.php page like you suggested. I created a new file at:
twentyfourteen-child\buddypress\members\single\home.phpEven just copying the exact same file over from the buddypress members\single folder broke the page (lost most of the styling and item body and left sidebar etc) so clearly I’m doing this wrong.
I think I need to have a better idea of how template overriding works. I’ve searched through the codex but have not been able to find anything that helps. What’s the best place to learn more about that? A how-to tutorial or something like that would be great.
Thanks again for the help and support,
BenI’m still struggling with this. Would anyone be able to point me in the right direction?
Thanks,
Ben