Support

Account

Home Forums Add-ons Options Page Cache ACF fields stored in the wp_options table

Solving

Cache ACF fields stored in the wp_options table

  • If your site has lots of ACF fields stored in the options table the site will perform tons of queries to the database, one for each of the fields you’ve created using register_field_group.

    In all, a single page load could do as much as 1000 queries before presenting the page to the user when fetching some the fields for use on the front end.

    Editing the plugin to dump the entire wp_options table and letting php parse the array cut down the total db query time to a fraction of the previous time.

  • Agreed. I’m using custom fields for taxonomy terms… so if you have a taxonomy with 250 terms and I have to cross check with wp_options for say… 2 custom fields… the number of queries goes from 1 with get_terms() to 500 when I have to loop through every one to get it’s associated custom field in wp_options. Brutal. Adds 5 seconds to page load time. There must be some better way?

  • Recently, the developer has made plans to allow options values to be set to autoload. See this topic http://support.advancedcustomfields.com/forums/topic/autoload-options/. I’m not sure if this would include taxonomy fields.

  • While this will be hopefully be fixed/improved due to the autoloading options, if you have templates fetching a huge number of options fields like this you can build a caching system yourself – hook into the edit_category (or similar) filters; fetch all of the relevant fields for the page and cache them in an array in a single autoloaded option. That way all of the queries only need to be run when saving/creating/deleting a category, rather than on the frontend.

  • @triplem,

    This does seem to be a good place to apply an object cache. Hadn’t thought of that before, which is odd since I have an object cache in the WP repo 😛

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.