1
votes

-I have successfully added a new tab to the Buddypress profile page and I also have my custom tab displaying my custom recipes template located in (buddypress/members/single/recipes.php)

function my_setup_nav() {
  global $bp;

  bp_core_new_nav_item( array( 
      'name' => __( 'My Recipes', 'buddypress' ),
      'parent_slug' => $bp->profile->slug,
      'slug' => 'recipes', 
      'position' => 30,
      'screen_function' => 'my_item_one_template',
      'default_subnav_slug' => 'recipes' 
  ) );

}

add_action( 'bp_setup_nav', 'my_setup_nav' );

function my_item_one_template() {
    add_action( 'bp_template_content', 'my_item_create_screen' );
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}

function my_item_create_screen() { 
    locate_template( array( 'buddypress/members/single/recipes.php' ), true );
}

?>

Now I want to list all the users custom recipe posts in their profile page, so that other users can see what recipes the user they are currently viewing has created. This is my current code but it does not work properly. It just displays all recipes, not just the ones from that particular user.

<?php 
                $type = 'recipe';

                $args = array (
                 'post_type' => $type,
                 'author' => $bp->displayed_user->id,
                 'post_status' => 'publish',
                 'paged' => $paged,
                 'posts_per_page' => 10,
                 'ignore_sticky_posts'=> 1
                );
                $temp = $wp_query; // assign ordinal query to temp variable for later use  
                $wp_query = null;
                $wp_query = new WP_Query($args); 
                if ( $wp_query->have_posts() ) :
                    while ( $wp_query->have_posts() ) : $wp_query->the_post();
                        echo '<h2><a href="' . get_the_permalink() . '">' . get_the_title() .  '</a></h2>';

                        echo '<div class="entry-content">';
                        the_content();
                        echo '</div>';
                    endwhile;
                else :
                    echo '<h2>Not Found</h2>';
                    get_search_form();
                endif;
                $wp_query = $temp;
?>
1

1 Answers

0
votes

You're trying to use $bp without including it as a global. But you don't need it.

Try changing

'author' => $bp->displayed_user->id,

to

'author' => bp_displayed_user_id(),