Skip Navigation

[Resolved] Check if user has viewed a specific post

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 8.90 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 6 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#610517

Is it possible to somehow check if a user has "read" a post?

I'm setting up a notification counter thing for unread posts.

Some direction would be appreciated!

Cheers.

#610624

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Brad

That's not really something Toolset can help you with, you'll need to write some custom code for that.

Depending on your requirements, it might make sense for you to record which posts a user has seen (i.e. store the data as user meta) or which users have seen a post (i.e. store the data as post meta).

I think the most reliable way to trigger your code, i.e. when someone visits a post, is to add your code directly to the template for displaying single posts.

If this refers to a custom post type, e.g. "Things", then you could duplicate the generic single.php and save a version single-thing.php which is used just for the thing post type. (You'll want to be doing this in a child theme.)

So whenever a thing post is loaded, you can use get_current_user_id() (https://developer.wordpress.org/reference/functions/get_current_user_id/) to see who is viewing the post, and then update either the user meta or post meta accordingly.

You'll need to decide the best format to record the post ids (if storing as user meta) or user ids (if storing as post meta), and that decision may depend on how and where you intend to display information about the number of read (or unread) posts, which are likely to involve writing custom queries.

The sidebar lists Toolset Contractors you could contact to do this for you, although as it is not specific to Toolset you should find any WordPress developer would be able to implement it.