Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reset BuddyPress WP_Query to single post type page


  • Paresh Radadiya
    Participant

    @pareshradadiya-1

    I’m trying to get group navigation menu items to show on single cutom post type page but am completely unsure how to approach the problem.

    I’ve built my solution by setting current component and current group manually to be able to get group navigation tab items.

    function boss_set_current_groups() {
        global $bp;
    
        if ( is_singular('course')  ) {
            $group_data = groups_get_group(7);
            $bp->current_component = 'groups';
            $bp->current_item = 'literature';
            $bp->current_action = 'experiences';
            $bp->is_single_item  = true;
            $bp->groups->current_group->is_user_member = true;
            $bp->groups->current_group->is_visible = true;
    
            $bp->groups->current_group = $group_data;
            $bp->current_item = $group_data->slug;
    
            $bp->groups->nav = new BP_Core_Nav( $bp->groups->current_group->id );
        }
    
    }
    
    add_action( 'bp_setup_canonical_stack', 'boss_set_current_groups', 11 );
    
    function boss_options_nav_html() {
    
        if ( is_singular('course')  ) {
            
            global $group_nav_html, $bp;
            ob_start();
    
            bp_get_options_nav();
    
            $group_nav_html = ob_get_clean();
    
            $bp->current_component = '';
            $bp->current_item = '';
            $bp->current_action = '';
            $bp->is_single_item  = false;
            $bp->groups->current_group->is_user_member = false;
            $bp->groups->current_group->is_visible = false;
            $bp->groups->current_group = '';
            $bp->current_item = ''; 
        }
      
    }
    
    add_action( 'bp_screens', 'boss_options_nav_html', 1 );

    After generating navigation html, ideally i’d like to reset main query in WP_Query to single custom post type as BuddyPress also override WP_Query object, but I haven’t found a way to do that.

    Have any of you seen something like that? Or could you provide an educated guess of where I might look for more info?

    Any help or support would be greatly appreciated as I am stumped.

  • You must be logged in to reply to this topic.
Skip to toolbar