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.

Within one plugin file I have several calls to the same option in the database via get_option(). Does WordPress do a database query every time I use get_option()? Would it be better to get the option once and store it in a global variable?

share|improve this question
3  
this answer explains how options work. –  Milo Feb 21 '13 at 3:02
    
possible duplicate of Plugin options autoloading –  s_ha_dum Feb 21 '13 at 5:17
add comment

1 Answer

up vote 0 down vote accepted

Wordpress will only do a database lookup the first time if the option hasn't been auto-loaded or already accessed prior. The performance hit is negligible, however if you're loading multiple separate options with a bunch of get_options instead of using the serialised option functionality, then the initial lookup * X number of separate option rows could potentially cause performance issues.

In your other question which is a duplicate of this one, I answer the question with an example of best practice code if you're concerned with get_option performance here.

share|improve this answer
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.