Skip to:
Content
Pages
Categories
Search
Top
Bottom

Showing WordPress Posts on Buddypress Activity


  • Dono12
    Participant

    @dono12

    I’ having this old but new issue. Old because I forget about it until there is a new Buddypress update, then I’m painfully reminded again.
    I’ve been showing User Posts to the WordPress site on the Buddypress Activity page by using an awesome function I found in a Forum. It adds a Button to Buddypress Nav, titled (POSTS), with post count. These are all the posts that a user posted to the WordPress site. The problem I’m having is everytime Buddypress comes out with a new Update I have to pass on it because it interferes with the (Posts) Nav and Vice Versa. I do not want to keep losing out on these updates but I also do not want to lose the user Posts button on the activity page.
    Here is the function I used, can anyone tell me how to fix this:

    
    
    /* ------------------------------Start BP Post in profile code for function-------------------- */
    function importSomething(){
    return include_once 'bp-custom.php';
    }
    add_action( 'bp_setup_nav', 'buddyboss_child_bp_nav_adder' );
    add_action( 'bp_template_content', 'profile_buddyboss_child_loop' );
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    
    function buddyboss_child_bp_nav_adder() {
    global $bp;
    $post_count = count_user_posts_by_type( $bp->displayed_user->id );
    bp_core_new_nav_item(
    array(
    'name' => sprintf( __( 'Posts <span>%d</span>', 'my-poems' ), $post_count ),
    'slug' => 'Articles',
    'position' => 250,
    'show_for_displayed_user' => true,
    'screen_function' => 'buddyboss_child_list',
    'item_css_id' => 'articles',
    'default_subnav_slug' => 'public'
    ));
    }
    function buddyboss_child_list() {
    add_action( 'bp_template_content', 'profile_buddyboss_child_loop' );
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }
    /*------- This is end of the code for above function ---------*/
    function profile_buddyboss_child_loop() {
    $myposts = get_posts(  array(
    'posts_per_page' => -1,
    'author'         => bp_displayed_user_id(),
    'post_type'      => 'post'
    ));
    if( ! empty($myposts) ) { 
    foreach($myposts as $post) {
    setup_postdata( $post );
    if (has_post_thumbnail( $post->ID ) ):
    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'sidebar-smallthumbnew' );
    else :
    
    $image[0] = "http:/...com/wp-content/uploads/2015/10/userpost.jpg";
    endif;
    
    echo '<li class="sidebar mostpop post-' . $post->ID . '"><span id="postimage"><a href="' . get_permalink($post->ID) . '"><img src="' . $image[0] . '" /></a></span><div id="postinfo"><a href="' . get_permalink($post->ID) . '">' . get_the_title($post->ID) . '</a></div></li>';
    }
    echo '</ul>';
    wp_reset_postdata();
    } else { ?>
    <div class="info" id="message">
    <p><strong><?php bp_displayed_user_fullname(); ?></strong> has No posts.</p>
    </div>
    <?php }
    }
    /* This is end of the code for above function */
    remove_filter('bp_setup_nav','');
    function count_user_posts_by_type( $userid, $post_type = 'post' ) {
    global $wpdb;
    $where = get_posts_by_author_sql( $post_type, true, $userid, true);
    $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
    return apply_filters( 'get_usernumposts', $count, $userid );
    }
    /* ------------------------------This is end of the code for post in profile above function-------------------- */
  • The topic ‘Showing WordPress Posts on Buddypress Activity’ is closed to new replies.
Skip to toolbar