0

I have added a new tab for profile tab using following code.

add_action('bp_setup_nav', 'mb_bp_profile_menu_posts', 301 );
function mb_bp_profile_menu_posts() {
global $bp;
bp_core_new_nav_item(
    array(
        'name' => 'My Posts',
        'slug' => 'posts', 
        'position' => 11, 
        'default_subnav_slug' => 'published', // We add this submenu item below 
        'screen_function' => 'mb_author_posts'
    )
);
}

I need to show 5 latest posts from the user in this tab. How to do it? (Currently when click the “My Posts” tab it says 404 error.

1

Please check the code below. I guess you are facing 404 because it's not getting the slug & the url properly.

add_action( 'bp_setup_nav', 'mb_bp_profile_menu_posts' );
function mb_bp_profile_menu_posts() {
    global $bp;
    bp_core_new_nav_item(
        array(
            'name'                => 'My Posts',
            'slug'                => 'myposts',
            'position'            => 11,
            'default_subnav_slug' => 'published',
            'screen_function'     => 'mb_author_posts',
            'parent_url'          => bp_displayed_user_domain() . '/myposts/',
            'parent_slug'         => $bp->profile->slug,
            'default_subnav_slug' => 'myposts',
        )
    );
}

function mb_author_posts() {
    add_action( 'bp_template_title', 'mb_author_posts_title' );
    add_action( 'bp_template_content', 'mb_author_posts_content' );
    bp_core_load_template( 'buddypress/members/single/plugins' );
}

function mb_author_posts_title() {
    echo 'My Posts';
}

function mb_author_posts_content() {
    echo 'Content logic goes here...';
}
0

BuddyPress plugin provides support for this question. This link will help you. https://buddypress.org/support/topic/creating-a-page-with-nav-tab-subnav-for-buddypress-profiles/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.