Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

From a performance only perspective, can anyone with more more experience of the WordPress core tell me if writing something like a post view counter to a separate table in MySQL would be quicker for read and writes compared to using a Custom Meta Field?

I know most people will answer with Custom Meta Field solely on the reason that it's best to use the Wordpress API/functions. However my past 12 years has been building PHP applications that handle millions of users/high traffic and I know caching is the answer but I am interested in improving MySQL queries as well.

Looking at a lot of other plugins, I have seen it done both ways (for the record I am not asking this question for use in a plugin it will be for personal use in a theme)

Can anyone tell me any pros and cons of each method?

For example when a page is loaded in WordPress, I have not looked at how it is pulling in the meta fields, if it pulls them all in 1 query, it might be faster to use a meta field vs making another query to a separate table.

share|improve this question
add comment

1 Answer 1

I can't really speak to the performance simply because I've not dug in to the internals. But from a pure logic approach the custom meta makes more sense to me.

The reason being that, at least from your description, you only really need a single field for each post/page. All you're doing is reading a value, incrementing it, and writing it.

Two lines of code using existing WordPress functions.

share|improve this answer
    
Hello, thanks for your comments. I agree on what you have said, I should say that my mention of writing a single column is just an example but I do think since it would be 1 column it would likely be better in a meta field, perhaps if I had a multi column table it would be more appropriate for a new table instead of the meta field. For example instead of just a view/hit counter it were to store the user ip, browser, and other analytic data –  jasondavis Nov 14 '12 at 21:30
2  
Perhaps you ought to edit your question so you can get more meaningful and relevant answers, comments, and advice. –  Stephen Nov 14 '12 at 21:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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