سؤال

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