Need help incrementing user meta data by 1 each time a page is visited

Can’t for the life of me figure out why this isn’t working, I’ve tried like below with $val, I’ve tried sticking the get_user_meta into the meta_value, I’ve tried just adding +1 in the meta_value but no matter what it always sets the value of the meta data to the number I’m trying to increment by so if its +1 it’ll be set to 1 and +4 to 4.

if(!get_user_meta(bp_displayed_user_id(), ‘page_visits’, true) >= 0){
update_user_meta(bp_displayed_user_id(), ‘page_visits’, 0);
}
$val = get_user_meta(bp_displayed_user_id(), ‘page_visits’, true) + 1;
update_user_meta(bp_displayed_user_id(), ‘page_visits’, $val);

Read more here:: Need help incrementing user meta data by 1 each time a page is visited

Leave a Reply

Your email address will not be published. Required fields are marked *