What is the most efficient way of implementing a favorite post system?

I am going to implement a favorite post system so users can save their favorite posts for later reading.

I want to know what is the best approach for doing it taking into considaration the possibility that hundreds of thousands of users will use this function. Users will be able to see their favorite posts in a custom page that will them.

I have thought of 3 different poissibles ways, I want to know which one would be the best performance wise.

1.- Saving all user ids as an array in a postmeta called favorites.

2.- Making a custom post type called favorites.

3.- Creating a new database table ‘wp_favorites’ that stores the post id, user id, and date of the created relationship.

So, which of those three would the best (as I said, performance wise)? And, what would be the pros and cons of each if any? If there is even a better way, please let me know.

3 Answers
3

Use a custom table. Create it as a network table, and store the site ID, so you can use just one table for the whole network.

row_id | site_id | post_id | user_id

There is no equivalent for such a table in the current core tables. Avoid serialized data, because that format is PHP specific, so you cannot read its data in any other language (including SQL), and sorting by or searching for any value is just awkward.

You have to track sites, users and posts now to delete matching entries whenever one of these objects is deleted.

Leave a Comment