Skip to:
Content
Pages
Categories
Search
Top
Bottom

Accessing Original $wp_query


  • WTHeel
    Participant

    @wtheel

    Hello,

    As I have read here, BP modifies the $wp_query object, rendering several WordPress functions useless inside the original loop.

    However, I need to access the page slug.

    I’m on http://www.domain.com/group/name-of-group/ and I need to access “name-of-group”. Any suggestions? For what it’s worth, I am trying to do so in buddypress.php right after header() — in the loop or out of the loop, it doesn’t matter. I just don’t want to resort to parsing the URL.

    Thank you.

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

  • shanebp
    Moderator

    @shanebp

    Did you try:
    bp_get_group_slug();


    WTHeel
    Participant

    @wtheel

    I just did, but it did not work. I looked at the function, saw $groups_template, and added the following inside and outside of the loop:
    var_dump($groups_template);

    Here’s the code from buddypress.php:

    <?
    /*
    Template Name: BuddyPress
    */
    
    get_header(); 
    $plp_user_check = plp_user_check($current_user);
    	var_dump($groups_template);
    	echo "<br>Course Path: " . bp_get_group_slug();
    include("forums-header.php");
    ?>
    
    <?	if( have_posts() ): ?>
    
    		<? 	while( have_posts() ): the_post();
    				var_dump($groups_template);
    				echo "<br>Course Path: " . bp_get_group_slug();
    				the_content();
    			endwhile; 
    		?>
    
    	<? else: ?>
    
    		<div id="post-404" class="noposts">
    
    			<p><? _e('None found.','example'); ?></p>
    
    		</div><!-- /#post-404 -->
    
    	<? endif; wp_reset_query(); ?>
    
    </div><!-- /#bodyContainer
    <?	get_footer(); ?>

    The first var dump just returned “NULL”. The second one returned:

    object(stdClass)#644 (1) { ["group"]=> NULL }


    shanebp
    Moderator

    @shanebp


    WTHeel
    Participant

    @wtheel

    I hadn’t seen that. Very helpful. Thank you.

    For others:

    $var = $bp->groups->current_group->slug;

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Accessing Original $wp_query’ is closed to new replies.
Skip to toolbar