Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

GOAL

We have several plugins in Buddypress to display posts in member's profile page (posts of displayed user), some of them doesn't work anymore (bp-posts-on-profile) or new one (TCH_PostsOnProfile) and some of them which works like (buddyblog) doesn't show multiple custom post types yet, I have decided to try to do it without a plugin, with the help of this site I have collected some snippets and have created almost working new tab with member's custom posts with if conditional for user roles who created specific post types. I have succesfully added a new tab in member's profile in buddypress with code below in bp-custom.php

PROBLEM

After adding snippet in bp-custom.php and creating stats-profile.php template I have tried many combinations of different codes, but I cant's see anything yet, only empty broken profile page with member submenu and (missing footer and sidebar)

CONCLUSION

How can I display custom posts for custom user roles? Every user role has a different forms to fill out and those submitted forms I would like to display in their profiles with the help of new added tabs.

EXAMPLES

Job Applicant creates 2 custom post types: "portfolio" and "applicant", CPT "portfolio" is something like their curricullum vitae with personal data and photos, "applicant" is advertisement for searching for job. Agency creates agency portfolio (CPT "agency") and "employer" CPT (advertisement offering the jobs. User role Club creates CPT "club" etc.

bp-custom.php is here

// Set up Custom BP navigation
function my_setup_nav() {   
   if ( user_can( bp_displayed_user_id(), 'job_applicant' ) ) {  
   global $bp;
      bp_core_new_nav_item( array(
            'name' => __( 'Stats', 'buddypress' ),
            'slug' => 'stats',
            'position' => 20,
            'screen_function' => 'profile_screen_stats' 
      ) );

      // Change the order of menu items
      $bp->bp_nav['messages']['position'] = 100;
  }
}

add_action( 'bp_setup_nav', 'my_setup_nav' );


// show feedback when 'Stats' tab is clicked
function profile_screen_stats() {
add_action( 'bp_template_content', 'profile_screen_stats_show' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}

function profile_screen_stats_show() {
// call your stats template
locate_template( array( 'stats-profile.php' ), true );
}

in stats-profile.php page I am trying to display those posts, this is the code I think that should suite my purpose best, template is in bp-default folder.

<?php 
  global $bp;
  global $paged;
  global $wp_query;
  $temp = $wp_query;
  $wp_query = null;
  $user_id = $bp->displayed_user->id;
  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  $args = array(
        'posts_per_page' => 10,
        'cat' => -1,
        'post_type' => array( 
            'post',
            'portfolio',
            'applicant',
            'agency',
            'employer'  
         ),
        'author' => $user_id,
        'paged' => $paged
    );
 $wp_query = new WP_Query($args);
  while ( $wp_query->have_posts() ) :   $wp_query->the_post();
    the_title();
  endwhile;
  $wp_query = null; $wp_query = $temp;
 ?>
share|improve this question

1 Answer 1

up vote 0 down vote accepted

This is the updated working code in stats-profile.php which together with code above in bp-custom.php (buddypress functions.php) gives me the title(s) of displayed user for multiple custom post types.

<?php
        if ( is_user_logged_in() ):

        query_posts(array(
                'post_type' => array( 
            'post',
            'portfolio',
            'applicant',
            'agency',
            'employer'  
         ),
                'author' => bp_displayed_user_id(),
                'showposts' => 3
            ) );  
        ?>
        <?php while (have_posts()) : the_post(); ?>
                <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>

        <?php endwhile;

        else :

            echo "";

        endif;
        ?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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