Cookies, or even HTML5 local storage, seem like a good way to implement this. Here’s some basic code that could serve as a starting point. Post IDs are stored as CSV in the cookie.
// Load current favourite posts from cookie
$favposts = (isset($_COOKIE['favposts'])) ? explode(',', (string) $_COOKIE['favposts']) : array();
$favposts = array_map('absint', $favposts); // Clean cookie input, it's user input!
// Add (or remove) favourite post IDs
$favposts[] = $post->ID;
// Update cookie with new favourite posts
$time_to_live = 3600 * 24 * 30; // 30 days
setcookie('favposts', implode(',', array_unique($favposts)), time() + $time_to_live);
Related Posts:
- Automatically delete inactive users after 2 months
- Force display name as full name
- How to discover and delete unused accounts?
- How do I properly format the user_role array?
- User fields that can be edited by administrator?
- Does wp_delete_user() remove all user content?
- How to delete all post and attachments of a user when I delete it?
- Bulk delete users from a csv list
- WP not logging in at first time
- Restrict access to non-wordpress section of site with user roles?
- Delete a user from frontend
- New User Save Filter
- Privilege to recover trashed posts
- How to verify which WordPress user requested the API in ASP .NET Core?
- Authentication between two different sites using the WordPress login cookie
- Use WP cookie to authentificate user on an external app
- The same session information for peer users on two different WordPress servers
- How can I save cookies to members
- is_user_logged_in() not working after domain change
- How do I add a field on the Users profile? For example, country, age etc
- user_login vs. user_nicename
- WordPress usermeta scaling for thousands of users
- Groups of capabilities: users with multiple roles?
- Is there a way to merge two users?
- How to restrict access to uploaded files?
- Why are user address fields required [closed]
- Importing users? From another wordpress site
- How can I add a user through SQL?
- Modify custom Users Manage page
- Copy a user from one WordPress site to another
- Count user posts by type and date
- Assigning tags to user?
- Get user info outside WordPress
- How to change the order in which users are displayed in admin?
- Total number of authors with more than one post
- WordPress has a trash for users? (Wrong result for count_user, greater than expected)
- Is there a simple way to manage capabilities per user?
- Check for user meta data at Login
- Buddypress – Send New User Activation Link to Admin [closed]
- Community and User Generated Content Website: Have been thinking about Drupal but leaning on WordPress heavily
- Redirect after users complete profile form
- Memory usage for scalable usermeta queries
- How to get current user’s phone number
- Front End Registration Form Code – Password Field Not Saving
- Updating Custom WordPress User Meta Field via REST API
- How do I customize the dashboard?
- How would I hook into `clear_auth_cookie` to return the user’s ID that’s currently being logged out?
- Make custom user table column filterable
- New users not showing up in Post -> Edit
- How can i change the name order in the admin?
- WP_User_Query by meta_value with Number returns nothing
- How to add user from front end
- Rewrite Rules and Login Issue
- User profile updates password even if not filled (Theme my login) in Firefox? [closed]
- Preventing auto-filling of e-mail addresses on profile.php
- users and usermeta table
- Prevent subscribers to changing certain profile fields
- How can I prevent certain custom roles from seeing other custom roles on the user list page?
- Creating User Profiles using author.php
- “the_author_meta(‘url’)” not working inside “href”
- REST API: wp_get_current_user not working on second call
- How to let the users edit their user names?
- How do I filter users based on email address?
- What’s the correct way to add capabilites to user roles?
- Web app vs CMS backend
- How to count total words for posts published by one author?
- Should I setup frontend-only users as CPT or use a plug-in?
- user login and its profile
- Delete all users with Editor role and their content mysql
- Load Custom Field to User Profile as per User Role using Ajax
- Show posts who published after registration date
- How to hide “Change role to” dropdown on Users admin menu
- How to display a calendar with events depending on the user?
- How to show different pages for different users
- How can i display pagination in custom comment list?
- hide page menu from admin panel for specific users
- How to save history in the client’s browser without login? [closed]
- Single Sign On (SSO) between two WordPress websites
- Disabling user capability to edit_posts or delete_posts in the front-end
- Redirect /member/ to /member/user
- get user id in a plugin without a function
- WP_User object behaving strangely when used inside Admin Panel?
- REST_query_vars for users
- How to use a transient inside WP_User_Query
- Allowing users to edit only their page and nobody else’s
- Let user delete comment on front end only
- Add an ‘edit profile’ page with Genesis
- Exclude Current user email and send notification
- Disallow user registration/checkout via Hotmail/Yahoo
- User management missing after migration to new host
- Add new user and user bio at same time
- Validate user meta and redirect
- Let admin users edit member profiles from front end
- Is it possible to tell if a user is logged into WordPress from looking at the cookies which are set?
- New User Registration email
- WordPress – Security Question at Login from User’s Meta Data
- determine active user browser at the same time
- get Discussion setting in wordpress
- Set a minimal number for next user_id
- Remove My Account Menu items in Woocommerce based on user roles