Skip to:
Content
Pages
Categories
Search
Top
Bottom

wp_bp_activity_sitewide and item_id problem

  • Hi,

    I was using buddypress rc1 and those days item_id was id of blog on which message was posted when component_action was new_blog_post. After upgrading to rc2 it is something else – like auto incrementing… How can i return to saving blog id?

    Or – is there another way to get out of database latest posts with their url and tags? i was using sth like:

    $result = mysql_query(\"

    SELECT primary_link,name,date_recorded

    FROM

    wp_bp_activity_sitewide

    INNER JOIN

    $posts_table

    ON $posts_table.post_date=wp_bp_activity_sitewide.date_recorded

    INNER JOIN

    $term_relationships_table

    ON $posts_table.ID=$term_relationships_table.object_id

    INNER JOIN

    $term_taxonomy_table

    ON $term_relationships_table.term_taxonomy_id=$term_taxonomy_table.term_taxonomy_id

    INNER JOIN

    $terms_table

    ON

    $term_taxonomy_table.term_id=$terms_table.term_id

    WHERE

    date_recorded =\'$time\'

    AND component_action=\'new_blog_post\'

    AND post_type=\'post\'

    AND taxonomy=\'post_tag\'

    ORDER BY date_recorded

    \");

Viewing 4 replies - 1 through 4 (of 4 total)

  • Burt Adsit
    Participant

    @burtadsit

    I’m not sure what the taxonomy tables have to do with anything but you can upgrade to 1.0 now. There are many new theme author friendly templates, templatetags that can do what you want alot easier than sql queries.

    https://codex.buddypress.org/developer-docs/custom-buddypress-loops/

    sql queries – because I wanted to use this script outside of buddypress installation.

    taxonomy tables – as I said I need to get tags of newest posts sitewide.

    As I see I can use bp_has_activities() to get recent posts without sql queries, but what about tags of those articles?

    any suggestions?

    Just in case anybody get into the same trouble – i didn’t managed to get to know why secondary_item_id is now unused, but i wrote my own function to overwrite this behaviour

    //HOOKS FOR BP_BLOGS TO SAVE AS SECONDARY ITEM ID BLOG ID

    function my_bp_blogs_record_post( $post_id, $blog_id = false, $user_id = false ) {

    global $bp, $wpdb;

    $post_id = (int)$post_id;

    $post = get_post($post_id);

    if ( !$user_id )

    $user_id = (int)$post->post_author;

    if ( !$blog_id )

    $blog_id = (int)$wpdb->blogid;

    /* This is to stop infinate loops with Donncha’s sitewide tags plugin */

    if ( (int)get_site_option(‘tags_blog_id’) == (int)$blog_id )

    return false;

    /* Don’t record this if it’s not a post */

    if ( $post->post_type != ‘post’ )

    return false;

    if ( !$is_recorded = BP_Blogs_Post::is_recorded( $post_id, $blog_id, $user_id ) ) {

    if ( ‘publish’ == $post->post_status && ” == $post->post_password ) {

    $recorded_post = new BP_Blogs_Post;

    $recorded_post->user_id = $user_id;

    $recorded_post->blog_id = $blog_id;

    $recorded_post->post_id = $post_id;

    $recorded_post->date_created = strtotime( $post->post_date );

    $recorded_post_id = $recorded_post->save();

    bp_blogs_update_blogmeta( $recorded_post->blog_id, ‘last_activity’, time() );

    bp_blogs_record_activity( array( ‘item_id’ => $recorded_post->id, ‘secondary_item_id’ => $blog_id, ‘component_name’ => ‘blogs’, ‘component_action’ => ‘new_blog_post’, ‘is_private’ => bp_blogs_is_blog_hidden( $recorded_post->blog_id ), ‘user_id’ => $recorded_post->user_id, ‘recorded_time’ => strtotime( $post->post_date ) ) );

    }

    } else {

    $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );

    /**

    * Delete the recorded post if:

    * – The status is no longer “published”

    * – The post is password protected

    */

    if ( ‘publish’ != $post->post_status || ” != $post->post_password )

    bp_blogs_remove_post( $post_id, $blog_id );

    // Check to see if the post author has changed.

    if ( (int)$existing_post->user_id != (int)$post->post_author ) {

    // Delete the existing recorded post

    bp_blogs_remove_post( $post_id, $blog_id );

    // Re-record the post with the new author.

    bp_blogs_record_post( $post_id );

    }

    $recorded_post = $existing_post;

    /* Delete and re-add the activity stream item to reflect potential content changes. */

    bp_blogs_delete_activity( array( ‘item_id’ => $recorded_post->id, ‘secondary_item_id’ => $blog_id, ‘component_name’ => ‘blogs’, ‘component_action’ => ‘new_blog_post’, ‘user_id’ => $recorded_post->user_id ) );

    bp_blogs_record_activity( array( ‘item_id’ => $recorded_post->id, ‘secondary_item_id’ => $blog_id, ‘component_name’ => ‘blogs’, ‘component_action’ => ‘new_blog_post’, ‘is_private’ => bp_blogs_is_blog_hidden( $recorded_post->blog_id ), ‘user_id’ => $recorded_post->user_id, ‘recorded_time’ => strtotime( $post->post_date ) ) );

    }

    do_action( ‘bp_blogs_new_blog_post’, $recorded_post, $is_private, $is_recorded );

    }

    remove_action( ‘publish_post’, ‘bp_blogs_record_post’ );

    remove_action( ‘edit_post’, ‘bp_blogs_record_post’ );

    add_action( ‘publish_post’, ‘my_bp_blogs_record_post’ );

    add_action( ‘edit_post’, ‘my_bp_blogs_record_post’ );

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_bp_activity_sitewide and item_id problem’ is closed to new replies.
Skip to toolbar