Skip to main content
1 of 2

Show users last read posts for each user?

Hello guys i'm trying to get logged in users most recently read 10 posts to show on their profile.

For example, user A's most recently read 10 posts user B's most recently read 10 posts...

i tried creating this short code to do it, but it doesn't show me any result either error. how can i fix this ?

function shortcode_recent (){
if( is_user_logged_in() ) {
 $post_id= get_the_ID();
    update_post_meta( $post_id, 'post_readed_by', get_current_user_id() );
    $args = array(
    'posts_per_page'   => 10,
    'meta_key'         => 'post_readed_by',
    'meta_value'       => get_current_user_id(),
    'post_type'        => 'post',
    'post_status'      => 'publish',
);
$posts_array = get_posts( $args );
foreach ( $posts_array as $post ) : setup_postdata( $post );

    the_title();
    if ( has_post_thumbnail() ) {
        the_post_thumbnail();
    } 
    the_content();

endforeach; 
wp_reset_postdata();
}

}
add_shortcode('post_recent',shortcode_recent );