문제

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