0

I want to store list of user IDs in the post meta who have rated a post . So, for each post I will need to check the post meta to see if the user id exists in it or not.

So my question is that, is it good idea to store that information in the post meta OR should I create a table and add it in the table. Will there be any difference in the performance (table vs meta) if the number of values grow very much?

I would prefer to store in the post meta as it is much simpler and cleaner way, but I have read one answer which says

never, ever, ever, use an EAV (aka the post_meta table) to store data that you might to need to query.

  • are you actually querying on the values stored in the field, or are you just loading the contents of the field and checking their values via php? – Milo Nov 3 '13 at 19:31
  • when a user clicks to vote, i get the value of that post meta and check if the user id exists in that (using php explode and foreach). If it does not exist then i add the user id in it. – enam Nov 3 '13 at 19:36
0

Based on your comment:

when a user clicks to vote, i get the value of that post meta and check if the user id exists in that (using php explode and foreach). If it does not exist then i add the user id in it.

there's no query involved there, so it's perfectly fine to use post meta for that purpose.

A query would be something like "load all posts from database where user with ID n has voted". That would be more difficult to achieve, as it's a many-to-many relationship, which WordPress doesn't do natively. Storing user IDs as serialized data (an array) is a PHP construct, MySQL doesn't "understand" that data natively, so that would not be a good use of post meta.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.