Skip to:

Looking for code snippet to add member’s recent posts to profile

  • prockstar



    I’m looking for a specific function that I have not been able to achieve so far.

    I would like to show the recent posts on the member’s profile page authored by said member.

    Now, I have successfully added the recent posts to the “home” page of the member page via widgets added in the WP customizer. The main issue I have is the styling, the featured image shows up huge, and the title get’s blended in with the content. It looks awful. There aren’t any styling/layout options on the widget as I’m guessing it’s intended for a sidebar.

    Soooo, I would like to create a custom template page and I have been able to pull the correct template file into my child theme. What I’m missing is the code snippet to pull in the recent posts of the member being viewed. I’ve tried a couple of snippets from around the web, but I haven’t been able to get anything to work.

    I even started to just style the “Latest Articles” section but the featured image is pulled inside the paragraph which won’t allow me to display none on the content. I’m looking to just get a simple five item list of the most recent articles with a 100×100 thumbnail.

    I would prefer not to depend on another plugin if possible.

    Would love to get some direction, maybe where I can find code examples I can use etc.

    Thank you … Scott

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

  • Prashant Singh


    Hi prockstar,

    Please try this code and can put your HTML accordingly.

    $user_id = bp_displayed_user_id();
    $user_query = new WP_Query( array( 'author' => $user_id,) );
    if ( $user_query->have_posts() ) :
    	while ( $user_query->have_posts() ) : $user_query->the_post(); ?>
    		<h2><?php the_title(); ?></h2>
                    the_post_thumbnail( 'thumbnail' ); 
    else : ?>
    	<p><?php esc_html_e( 'Sorry, no posts created by this member.' ); ?></p>
    <?php endif; ?>




    Thanks prashantvatsh,

    This gets me moving in the right direction.

    … Scott

    Prashant Singh


    Great to hear that it helped you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar