Loop for displaying connected users
-
I’m trying to find a loop that can display all of the posts connected to the user on the user’s buddypress profile page.
Here’s my code
// Assign badge to user meta using Post-to-Posts Plugin function my_connection_types() { p2p_register_connection_type( array( 'name' => 'multiple_authors', 'from' => 'badge', 'to' => 'user', //'to_query_vars' => array( 'role' => 'editor, author' ) ) ); } add_action( 'p2p_init', 'my_connection_types' ); <?php // Looping through badges on user profile //////////////////// ?> <p class="badges"><strong>Badges:</strong> <ul class="badges"> <?php // show badges from posts-to-posts functions $connected = get_posts( array( 'connected_type' => 'multiple_authors', 'connected_items' => $user, 'suppress_filters' => false, 'nopaging' => true, ) );
Here’s the first display loop I tried
add_action( 'bp_before_member_header_meta', 'display_custom_usermeta' ); // place the author box on member profile in buddypress function display_custom_usermeta() { ?> <div class="custom_usermeta"> <?php // Display connected badges foreach ( $connected as $post ): ?> <li class="badge"><a href="<?php echo($connected->post_url); ?>"><?php echo($connected->post_title); ?></a></li> <?php endforeach; ?> </ul> </p> }
Here’s the second loop I tried
if ( $connected->have_posts() ) : ?> <h3>Badges:</h3> <ul> <?php while ( $connected->have_posts() ) : $connected->the_post(); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul> <?php wp_reset_postdata(); endif; ?> </ul> </p> <?php }?>
Unfortunately neither of these produces the intended results.
- The topic ‘Loop for displaying connected users’ is closed to new replies.