[Resolved] Show member recent post in members loop
-
Hey guys
The ‘posts’ that my members create are the most important aspect of my site. I’m successfully showing the most recent ‘posts’ by an author on their profile using even though it is out of date
What I need to do next is show one recent post by each author on our members home page, presumably within members-loop.php
Is there a way to get this most recent post here?
Many thanks,
Ian
-
Does anyone know of a way do get most recent post in the members loop for each author? Thanks.
Sorry to spam, but totally stuck on this, any ideas?
@applegateian see how it’s done in BuddyBlog http://buddydev.com/buddypress/introducing-buddyblog-allow-users-to-blog-from-their-buddypress-profile/
Thanks @mercime – however, I’m already successfully showing users posts on their profile – see below. I’m doing this using posts-on-profile but it’s quite out of date:

What I can’t do, is show the most recent post for each user on the members list (on the members home page) – note the placeholder image on the right for each member:

Hope someone can help!
Try putting this in members-loop.php
<?php $user_id = bp_get_member_user_id(); $query = new WP_Query( 'author=' . $user_id ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); //display title the_title(); //display content the_content(); } } //reset for next member wp_reset_postdata(); ?>@henrywright-1 that works!
I need to show the featured image, and link to the profile, so I added the following, but it’s just pasting the image URL, how do I add img src to that and the link to the post?
<?php $user_id = bp_get_member_user_id(); $query = new WP_Query( 'author=' . $user_id ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); //display title the_title(); //display content the_content(); //featured image the_field('featuredimage'); } } //reset for next member wp_reset_postdata(); ?>Do you mean this “the_field(‘featuredimage’);” is displaying the feature image URL? If it is, then you can just wrap some HTML around it:
<?php $user_id = bp_get_member_user_id(); $query = new WP_Query( 'author=' . $user_id ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); //display title the_title(); //display content the_content(); ?> <a href="<?php the_permalink(); ?>"> <img src="<?php the_field('featuredimage'); ?>" alt="" /> </a> <?php } } //reset for next member wp_reset_postdata(); ?>Oh it’s actually THAT simple? Thanks so much, I’m enjoying learning from you guys 🙂
Yep! not really that hard at all :} Check out the WordPress Codex, you’ll find lots of useful info on there…
OK it works really really well – except, it brings in not just the most recent, but 3 recent posts, can I limit the number?
You should be able to.
Try changing
$query = new WP_Query( 'author=' . $user_id );to
$query = new WP_Query( 'showposts=1&author=' . $user_id );Cool @henrywright-1 that’s got it. I found that showposts query, just wasn’t implementing it correctly. I owe you a pint (or 4).
Great stuff, glad you got it to work!
Yep, works like a charm 🙂

I would like to ask to @henrywright-1
how could I display 1 latest post from different custom post types, I have several CPT posts as a “portfolio”, “applicant”, “employer”. I would like to display 1 latest post from every custom post type (if exists because for example CPT applicant creates user role applicant, so it is not an employer), I don’t need featured photos etc, only one recent post (custom post type) with permalink to every Custom POST TYPE (where exists obviously).
For exampleJohn Doe
latest post from “portfolio”: John Doe Portfolio
latest post from CPT “applicant”: John Doe applicant
latest post from CPT “images”: John Doe’s latest imagesI have installed excellent Buddyblog plugin but it shows me only one post or custom post type, not more than one, so I use it only for simple posts, but I also want to show custom post types on member’s profiles.
$query = new WP_Query( 'post_type=portfolio' );More info on how you can use the WP_Query class:
- The topic ‘[Resolved] Show member recent post in members loop’ is closed to new replies.
