In my list of members, I show the standard fields of avatar, username, profile data, etc - this all works fine.

I'd like to also show the 'most recent post' from that user too.

Is there a snippet I can use to grab the most recent post from that author? Somehow identifying which author it is and their most recent post?

Thanks,

Ian

有帮助吗?

解决方案

Somebody provided me with a great fix for this:

<?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();
?>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top