Skip Navigation

[Resuelto] Check if user has viewed a specific post

This support ticket is created hace 6 años, 10 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Etiquetado: 

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Nigel hace 6 años, 10 meses.

Asistido por: Nigel.

Autor
Mensajes
#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

Idiomas: Inglés (English ) Español (Español )

Zona horaria: 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.