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 );
the_title();
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
the_content();
endforeach;
wp_reset_postdata();
}
}
add_shortcode('post_recent',shortcode_recent );