Skip to:
Content
Pages
Categories
Search
Top
Bottom

Using bp_blogs_get_latest_posts() Returns An Error

  • @katendarcy

    Participant

    Okay… This may be something completely straightforward, but: I’m trying to use bp_blogs_get_latest_posts() in order to retrieve the latest site wide posts and display them in a customized way. However, when I go to call the function, I get an error (“Call to undefined function”). Any idea what I could be doing wrong? The widget is displaying fine in the sidebar, and I’m under the impression this is the function it uses.

    Thanks in advance for the response!

Viewing 11 replies - 1 through 11 (of 11 total)
  • @katendarcy

    Participant

    I know bumping isn’t good forum etiquette, but… any ideas on this? Again, other functions and features of BuddyPress are working just fine. But, I can’t seem to get this function to work. I’d really appreciate any help or insights! Thanks!!!

    @boonebgorges

    Keymaster

    Not sure why bp_blogs_get_latest_posts() isn’t working for you, but you might try as a more future proof alternative (bp_blogs will be phased out) the activity loop https://codex.buddypress.org/developer-docs/custom-buddypress-loops/the-activity-stream-loop/

    So you’d have something like (off the top of my head – probably won’t work without tweaking!)

    <?php if (bp_has_activities( 'action=new_blog_post&max=5' ) : while ( bp_activities() ) : bp_the_activity(); ?>
    // use the activity loop functions to display information
    <?php endwhile; ?>
    <?php endif; ?>

    BTW – round here I don’t think bumping is too taboo, but the 13 hours between Friday night and Saturday morning are generally not a very busy time on the forums :)

    @katendarcy

    Participant

    Thanks for the recommendation! I’m going to have to read up on that. I’m still very new to BuddyPress, but I really like it. As a quick test, I copied/pasted the loop from the example Activity Stream Loop, and it seemed to work just fine. So, with some “tweaking”, I think it’ll be what i need.

    BTW – round here I don’t think bumping is too taboo, but the 13 hours between Friday night and Saturday morning are generally not a very busy time on the forums :)

    LOL! For the first part: good to know! For the second, well, the fact that it’s a “busy time” for me is only further proof I need to get out more! :D

    Thanks again!

    @boonebgorges

    Keymaster

    You got it! If you get a nice activity widget put together, I bet a lot of people would be interested in it – so don’t be shy about posting it here :)

    @apeatling

    Keymaster

    Much of the BuddyPress post and comment functions have been removed from 1.2.2 since they were no longer used at all. They were due for removal in 1.3 but I brought that forward because I didn’t want plugin devs making use of them. They are in the process of being moved to the back compat plugin. The activity stream tracks blogs, posts and comments and is a much better way (both performance and usability wise) of fetching the latest blog activity. Boone’s method is the way I would recommend.

    @katendarcy

    Participant

    @Boone I’ll keep that in mind about the widget!

    @Andy That makes sense. Thanks for the explanation.

    One more question, though just slightly off topic: Is there a way to access the activity (post) title itself? As I said, I’m trying to create a customized appearance. So, I don’t want: “John wrote a blog post on:”, but rather, just the post title. I’m able to draw the time since info by itself, but I can’t seem to figure out how to isolate just the post title. I’ve been through bp-activity-templatetags.php testing out some of the functions and looking over the code, but I can’t seem to figure it out… Any ideas?

    Thanks so much!

    @smuda

    Participant

    so same with

    BP_Blogs_Comment::get_total_recorded_for_user($bp->displayed_user->id);

    i guess.

    is there any way to get the total count of a users comments at the moment? i kinda don’t understands Boone Gorges code.

    @katendarcy

    Participant

    @smuda: Did you notice the link that Boone posted? A little farther down on that page there’s an example of how to display comments. ;) Also, there’s an activity loop example at the top of the page. (Heads-up: The only thing I noticed with the comments is mine didn’t appear right away with that. I’m not sure if there’s a cache issue or not.)

    EDIT: Hmmm… comment count still not appearing for me. Doesn’t mean it’s not a cache issue, I guess. But, I’d say it’s obviously still worth a shot for you smuda.

    @katendarcy

    Participant

    I’ve been working on this project off and on, but after coming back to this particular issue and still not seeing a straightforward solution, I decided to just use the PHP explode function. Obviously not completely ideal, but until I find an alternative, in this case, it should do. Here’s what I used in case anyone else would like to know:

    <?php
    $activityText = bp_get_activity_action();
    $activityTextNew = explode("post: ", $activityText);
    $activityPostTitle = explode('<span class="time-since">', $activityTextNew[1]);
    ?>

    Then you use the value of $activityPostTitle[0] for the title of the post:

    <?php
    echo $activityPostTitle[0];
    ?>

    Obviously this is dependent on the default text for bp_get_activity_action.

    @apeatling

    Keymaster

    The other option is to use the item_id and secondary_item_id inside the loop to fetch the actual post content. Of course the problem with that is it is very resource intensive. It’s probably not worth it.

    @katendarcy

    Participant

    @Andy Peatling Sorry, just saw your response to this… Thanks for the idea, though. : )

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Using bp_blogs_get_latest_posts() Returns An Error’ is closed to new replies.
Skip to toolbar