Support

Account

Home Forums General Issues Pre-loading get_field()

Unread

Pre-loading get_field()

  • We have an ACF driven page which yields around 450 queries of which are 400 from get_field() function calls. Although, our database is quite well optimized, and it usually takes ~0.1s to complete all those queries, we’d still like to optimize the it further because it can be a bottleneck during busy hours. We’ve researched caching plugins, but they cause a problem with our custom plugin which serves to show different content based on the visitor’s country and usually they just cache one version of the page (if there’s a plugin that can be tweaked to only cache certain files, not whole page or plugins – that would be great solution for us).

    I’ve read on couple of posts that if get_post_meta($postID) is called, it’ll query the database and cache the result so that when get_field($fieldName) is called it’ll load the data from cache and not from the database. This appears not to be the case because get_field() actually queries database 2 times even after get_post_meta() is called (calling get_field() again afterwards yields no additional queries, so it in fact caches it after first call, but it doesn’t read data from get_post_meta()). Another thing worth noting is that get_fields() is making ~400 queries as well. Based on my logic, get_fields() should do similar to get_post_meta() where it’ll load all fields in a single query but in fact it makes 2 queries per each field.

    I’m curious whether the above are bugs or intended behavior (and posts were just misleading)? Also, if it’s intended – are there any solutions available such as saving all custom fields values per post as a JSON and load that JSON in single query (so that it gets parsed into multiple fields later on)?

Viewing 1 post (of 1 total)

The topic ‘Pre-loading get_field()’ is closed to new replies.