This line is wrong.
if(!get_user_meta(bp_displayed_user_id(), 'page_visits', true) >= 0){
That is “not value greater than or equal to zero”. The NOT operator has precedence over the greater than comparison.
So, assuming the value is a number, then NOT a number evaluates to false. Then you are comparing false to greater than or equal to zero. False == zero, so this evaluates to true, which means that in your next line, you set it explicitly to zero.
So, the operator precedence is likely screwing you up. Try adding parentheses around your comparison before negating it.
if ( !( get_user_meta( bp_displayed_user_id(), 'page_visits', true ) >= 0 ) ) {
Also, counting page visits in user meta like this is fairly horrible for performance. Best to use some other real analytics solution.
Related Posts:
- Can I count the number of users matching a value in a multiple value key?
- Save custom user meta on registration
- How to get users by a custom field / by user meta data?
- How do you add a custom option to user data?
- Show User Their Password
- How to update serialized data in the user meta data
- How can I sort get_users() by any value (last_name, user defined fields and more)
- Displaying additional User Contact Information
- get_user_meta Short Profile Section
- Separate table or usermeta
- meta_query for a string inside a meta field containing a comma-separated list
- How to update custom user meta field in wp?
- WordPress User Profile Upload – If page is saved file reset
- ACF: How to get the full field name (meta_key) by a field key?
- How do I create a column in Users list and display user data from custom registration field
- How to save multiple options from a dropdown in user profile
- WP_User_Query pulling ACF to loop
- Users Select inside custom metabox
- query usermeta from custom field
- custom avatar removal
- How to add upload video option in wordpress for user?
- Passing args to WP_User_Query am I using meta correctly?
- How to save the date/time of last update of an extra user profile field?
- Show image if author meta (profile fields) exists outside loop
- ACF: How to get users with a ACF flexible content subfield with a specific value AND layout?
- How to add fields in custom registration form, validate it and aave to db? [closed]
- check for duplicate user meta data before updating
- Custom Field Repeating When Using foreach
- Front-End User Profile
- Get emails from users by custom field SQL
- award points to a user each time they update their cpt post
- How to update user profile custom fields
- Save custom field types with this function…?
- Display Additional Info
- Populate custom checkout fields with data from previous orders
- Add WordPress user custom meta to chartjs vertically stacked chart in Divi theme
- User query – getting values for custom meta keys/fields
- Delete user meta but only if found in array
- How to get data from user meta custom fields created with acf-pro plugin?
- How to save multiple values with same meta_key, each value linked to another tag id
- author.php not showing content if Author has no Posts
- Getting user’s data, by custom field lookup (meta)
- select user with all meta field and field value. I am use Below Query for this ,So any of know another way to fast query instead of below query?
- Redirecting to an external URL
- update_user_meta(): invisible data storage
- Extend WP_User_Query or WP_User to return all custom fields?
- Populate a select box with data stored in the database?
- Create custom fields/meta data gender+country – radiobuttons and dropdown on register screen for these fields
- Custom Meta Boxes and Fields for WordPress: Change directory upload based on user-edit page
- Is it possible in WordPress
- wordpress simple post multi rating with post_meta and user_meta
- How do i get a specific user metadata using custom metavalue outside of wordpress?
- Echo text if field under user_meta is empty with get_users()
- Custom registration form and custom field
- how to add radio field on user meta on function.php?
- Can’t sort custom column on user.php by number / meta_value_num?
- Add new “Insert Into Post” button with another function
- Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
- How to add new custom page or post blocks?
- Transients vs CRON +Custom Fields: Caching Data Per Post
- Unable to save datetime custom meta field using update_post_meta() function
- Using WP Query to search by multiple meta fields
- Get aggregate list of all custom fields for entire blog
- Can ordering post list by meta_value cause performance issue?
- woocommerce product custom field
- two custom fields question
- How to display multiple images in custom field
- How to show a gloabl message on a user profile page (in back end)?
- Display the contents of a custom field of a page on their child
- Read / Watch / Listen times – meta
- Login WP – Connect single field to an external api
- adding extra wordpress user info from registration form
- Custom Meta Box (SELECT) Not Saving
- Turn raw url into clickable links
- Advanced Custom Fields functionality without plugin
- Get post ids sorted by meta_key
- Advanced Custom Fields Plugin – Unable to get URL from post_object
- Plot location on Google map using full address specified in custom field
- Unable to get specific value from post meta
- 3.8 Media Upload and Custom Meta Box
- Displaying Custom Field Array
- Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
- Let’s Create Custom Field Template Documentation
- If one meta key value is empty, try to get another meta key, and if both meta keys are empty show something else?
- Save attachment ID instead of URL in custom field
- How to order posts by number of Vimeo Likes
- Displaying a video on the homepage via a custom field inside a php widget
- how to create meta key name in wp_usermeta table in database
- Display the output from Custom User Fields from a WordPress user profile on a WordPress Custom Page
- Show image depending on the number in the custom fields
- Save, update, get and sanitize post meta as HTML not plain
- Saving metadata of related post on save_post
- Custom field value link title
- How to Order Posts by Custom Fields?
- added a meta box to post however when saving menu while debug on throws a warning
- How can i get the actor birthday by date?
- Order by a meta field in query loop
- Add CSS class to posts with certain meta key
- Best way for managing images of ads banners
- Crop custom image size vs actual size