WordPress.org

Ready to get started?Download WordPress

Forums

Add all theme options as an array or as a single options in wordpress (3 posts)

  1. mo3aser
    Member
    Posted 1 year ago #

    hi,

    I developing a new wordpress theme with control panel has more than 100 option .. so I asked is it better to store all of this options as a one array and get it in a global variable and use it or store each option in a separate option ?

    what is the better for CPU usage and site speed . I noticed that the home page of the theme has a more than 120 queries

    thanks

  2. s_ha_dum
    Member
    Posted 1 year ago #

    120 queries is a lot. WordPress, imho, queries too much-- something like 16 per page load for a vanilla install-- but 120 is really a lot. I expect that will cause trouble on some lower end hosts. You should really make an effort to get that down.

    Will you be using all (or most) of these options every time you load a page or will you be using only a subset? Also think about whether you will need to query for particular values. If you are using most of the options every time and don't need to query for particular values, you will probably get better performance putting everything into one row in the database. If you will be using a few values for a page load, you may want to store those separately. If you need to run queries that search for particular values, you probably want them stored separately.

  3. Spencer Cameron
    Member
    Posted 1 year ago #

    Agreed. 120 queries = not so good. See which queries you can consolidate into a single query. It's better to query a few times and then pull the content from the queried data 120 times than to make 120 queries by a long shot. It could mean the difference between your site always crashing and never crashing. :)

    If storing your options as an array will be beneficial to you ( i.e. you would like to easily iterate through them after retrieval ), then I'd say go for it. An array of 100 options shouldn't be a problem as long as you're mindful of the total size of the array in bytes. A good rule to follow would be 300KB - 500KB at the most. Less than 50k would be even better. Don't store data much larger than that in the options table. :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.