Frage

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

War es hilfreich?

Lösung

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();
?>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top