Update user meta of author when post content is viewed


I have a value that I’m trying to store as user meta for authors on my site. I need it to update itself every time the content of a post is viewed for that author. Here’s as far as I’ve gotten but it isn’t storing the value. I use this in functions.php.

function user_score() {
    global $bp;
    $author_id = $bp->displayed_user->id; // do stuff to get user ID

    $author_posts = get_posts( array(
      'author' => $author_id,
      'posts_per_page' => -1
    ) );

    $counter = 0;
    foreach ( $author_posts as $post )
      $score = get_post_meta( $post->ID, 'ratings_score', true );
      $counter += $score;
    update_user_meta( $author_id, 'user_score', $counter );
    if ($echo)
      echo $counter;
    return $counter;
function update_user_score($content){
  global $post;
  return $content;


>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/update-user-meta-of-author-when-post-content-is-viewed/">

Update user meta of author when post content is viewed</a>
, , Pollux Khafra 1 week 0 Answers 20 views 0

Leave an answer