There are lots of actions you can hook into to do this, I think the best once to use would be wp
or template_redirect
.
Using either of those actions the code would be like this, this code goes into the functions.php
add_action('wp', 'bt_update_user_homepage_meta');
function bt_update_user_homepage_meta () {
// get user id, if user is not logged in then it will be 0
$user_id = get_current_user_id();
// now we check if we are in front page or not and we update the user meta accordingly
// if user is not logged in this code will try to update the meta for user 0,
// because this user doesn't exist, nothing will happen
if (is_front_page()) update_user_meta($user_id, 'pagehome', '1');
else update_user_meta($user_id, 'pagehome', '0');
}
Related Posts:
- Calling a method from functions.php on a click of a button
- Showing user ID on user main page from screen options
- Issue with foreach on duplicate meta_key’s
- get_usermeta() deprecated in favor of get_user_meta(). But why doesn’t it make use of it?
- How to display user nickname (not display name) in PHP template?
- Custom field value not saving when it contains a URL?
- Get all user meta by meta key instead of ID
- Create a new usermeta field for users
- How to get a list of all possible values of a specific user meta key?
- How do I display a user’s previous orders as a select box option on a product?
- How to use an associative array in post__in with WP_Query?
- How to check if a meta value has already been assigned to any user?
- adding custom user input fields in WordPress admin dashboard gives error The link you followed has expired. Please try again
- function to assign user role based on a field from usermeta
- How to upload a file to a folder named after the user_id via plugin
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
- Creating user status mode in WordPress
- How can I save unique user data on my site? [closed]
- Adding number to date not working [closed]
- Seach custom post type posts only by meta fields?
- How to abort saving data in save_extra_profile_fields function WordPress?
- Let Users Choose Post Categories
- Update user profile information from functions.php
- Sort meta-value in the sequence array in pre_get_post
- a:0:{} is replaced into database as s:6:”a:0:{}”;
- Grouping posts by a custom meta value
- Find a way to retrive data updated through metabox plugin to web page
- Read array in php?
- Countdown to date function?
- How to use array in function to get only value I want
- Getting users with a specific meta data and then querying their posts?
- Login redirect. Check user meta and redirect accordingly
- How to get specific attribute from DB
- If Array Values Match Another Array’s Values, Then
- User Meta Value not echoing despite Var_Dump Showing correct string
- Shortcode for Listing Users from Meta Value?
- Getting different user data depending on where I use variable
- Adding Author Box Meta Links with Co-Authors
- Get the users that my following users are following
- Comapare get_user_meta value
- How can get all users by current user meta?
- Edit Account – read and write to MySQL
- Uses for function: wp_update_user
- Update user repeater meta (ACF) with another user meta field value
- Create condition for Author bio Social Links
- How to store checkbox data for individual users?
- How do I Populate a Table Field with User Meta Data?
- Set all WooCommerce Products to Simple, Virtual & Downloadable
- how can i update my postmeta without losing old data?
- How to add and subtract user meta values after post meta update
- User meta needed in query is serialized – how to unserialize safely?
- Include User ID in iFrame URL
- WP custom posts: filter results to custom taxonomy tag that corresponds to user meta field
- Usermeta data unserialize, extract and display in table in WordPress
- Change user metadata on registration (show_admin_bar_front = false)
- Store data from JavaScript object to custom table in user account
- Export WordPress User Meta to CSV/Excel
- Updating User Profile information removes image
- How to change the value of a variable using input field?
- Display current user metadata on WordPress page
- How Can I Display the Last Modified Date for User Profiles on WordPress?
- Get user by meta data key and velue
- Where do I implement this display of User Meta Data, and how to put it in a table?
- Update an additional user meta field with a string
- Add another role to a user when they click a button?
- Store custom field’s multiple values in one user meta key
- Get field in readable word
- not able to access $_POST on backend profile update
- Right way to display the_author_meta fields?
- Get the total Author Favorited posts
- Adding user meta to post meta wp_insert_post() not working
- Get meta_query value by user meta array
- Creating a custom register form
- get_users when from meta key that has serialized values
- How can get all users by current user meta (array)?
- Store stripe info as user_meta
- Private messaging – Getting and displaying the avatar/url of a message recipient
- Updating custom user meta
- Updating meta_value in a custom key
- Display Content Based on Custom Field Value
- Limit the number of successful logins
- Get author meta of all writers
- Let users register weight each day and save it in DB
- Hide a nav menu item based on get_user_meta results
- A better way to write this php function
- How do I empty a specific meta_value for all users in PHP
- Import users and custom user meta from csv
- Search custom post type posts only by meta fields?
- probleme adding Txt and Links in preg_match()
- Configuring WP-CLI on Windows 10
- Adding ads code between comments
- only show container with next/prev links if they exist?
- JS file work only in index page
- Get posts from multiple post type
- Replace Woocommerce “add to cart” to be “Download” button [closed]
- JS value to PHP variable to change div background color with PHP If else statement
- Store post content in a php variable and output them using for loop
- Warning: call_user_func() expects parameter 1 to be a valid callback, function
- What is wrong with this piece of PHP code? This is for an email template. (I am completely new to PHP)
- html to posts, jpg to featured image, zip file contains jpg and html