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 shortcode 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 );

    if ( has_post_thumbnail() ) {


add_shortcode('post_recent',shortcode_recent );
  • See this answer. Oct 12, 2017 at 4:59
  • Before I attempt a full answer: 1) why not adding "last_read_posts" like meta field to the user instead the post? and 2) setting this field while users are reading the post using Javascript? Oct 13, 2017 at 17:21

1 Answer 1


You should use update_post_meta with post_readed_by meta key when a user visit each single post.

you can use the_content filter to update this with checking the is_singular()

Hope you know how to sort these

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.