0

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?

0

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.

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.