Skip to:
Content
Pages
Categories
Search
Top
Bottom

List or display posts on a user's profile


  • cyndimarie
    Participant

    @cyndimarie

    On each profile page I want to show the posts authored by that user. I’ve found a few other forum posts with a similar idea (see one HERE.)

    The sad thing is like a month ago I got this working, and then yesterday I accidentally overwrote the file. So I know it’s possible to do, I just can’t seem to remember how I did it and now I can’t get it to work. I had made the customizations in member-header.php and it showed the title and excerpt.

    Any help would be great!

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

  • cyndimarie
    Participant

    @cyndimarie

    Also let me add, I DO NOT want a separate tab for the posts, I just want them added to the profile page via member-header.php.


    danbp
    Moderator

    @danbp

    hi @cyndimarie,

    no idea of what you erased by error. 😉 But can this snippet help you ?
    Add it to bp-custom.php or functions.php

    function bpfr_get_post_on_profile() {
    	
    	$myposts = get_posts(  array(
    	'posts_per_page' => -1,
    	'author'         => bp_displayed_user_id(),
    	'post_type'      => 'post'
    	));
    	
    	if( ! empty($myposts) ) { 
    		
    		echo '<h5>My awesome posts:</h5>'; 
    		
    		echo '<ul>';
    		
    		foreach($myposts as $post) {
    			setup_postdata( $post );
    				echo '<li><a href="' . get_permalink($post->ID) . '">' . get_the_title($post->ID) . '</a></i>';
    		}	
    		
    		echo '</ul>';
    		
    			wp_reset_postdata();
    			
    	} else { 
    		
    		echo '<div class="info" id="message"><p><strong>'. bp_displayed_user_fullname() .'</strong> has No posts.</p></div>';
    	}
    }
    add_action ( 'bp_before_member_header', 'bpfr_get_post_on_profile' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List or display posts on a user's profile’ is closed to new replies.
Skip to toolbar