Support

Account

Home Forums General Issues Does hard coding ACF fields increase speed of wordpress?

Solved

Does hard coding ACF fields increase speed of wordpress?

  • I have around 300 custom fields setup in wordpress admin. My WP installation runs incredibly slow and I am looking at any possible way I can decrease load times. So recently I discovered that it is possible to export all the fields and just include this code in functions.php or another php file.

    I have a couple of questions regarding this.

    1. If I export all my fields and include it functions.php, can I delete all the custom fields groups from ACF in the wordpress admin? Would I lose any data from posts that use these fields?

    2. If I did this (include the code in a php file and delete all the fields from admin), would WP run faster?

    Thanks!

  • Hi,

    With ACF Pro (5) there’s also the possibility to have ACF save the fields to json files which will get loaded instead of loading from the DB (which will speed things up).
    http://www.advancedcustomfields.com/resources/local-json/

    But to answer your questions
    1. Yes you can delete the fields from wp-admin if you put them in a php file but it doesn’t really matter if they remain, ACF will just load them from the php file anyway. You would not loose any data if ACF fields are removed. In deleting fields or fieldgroups you’re not actually deleting anything from posts, terms, user etc. you’re just removing the GUI for working with the meta data. It’ll still be there in the database and you could retrieve them yourself using get_post_meta for example.

    2. I haven’t tested too much with the php inclusion but I’m pretty sure it’d be faster. However I’d very much recommend using the JSON method instead since that’ll mean you can still easily add, remove or modify your fields without having to export and paste the new php code everytime.

  • Hi Jonathan,
    Thanks so much for your reply.

    The JSON method is absolutely brilliant. So simple to implement and I definitely like the fact that I wouldn’t have to change the PHP code every time I add a new field…I was actually worried about having to do this.

    Just to clarify though, we are talking about load times being reduced through out the entire site right? Not just when loading the ACF groups in admin…right?

    I mean, when a post on the front end is being loaded, and this particular post uses 100 or more different ACF fields, will the JSON method reduce the time it takes to load this particular post?

    Thanks again

  • Hi,

    No problem 🙂 Yes the JSON feature is incredibly useful especially for me as a developer to keep fields in sync between enviroments.

    Unfortunately it will not improve performance in your theme where you fetch all the posts and their meta values. The get_field (and similar functions) are all basically wrappers for WordPress own functions such as get_post_meta etc. (they do some more stuff like changing the return value and setting up repeaters etc as well).

    The information always have to come from the database.. BUT! There is still stuff you can do.

    You can for example in some cases see improvement in performance if you use the get_fields function http://www.advancedcustomfields.com/resources/get_fields/.

    Or take it a step further and create your own transients in which you store some values so your visitor don’t have to fetch them dynamically on every page load. https://codex.wordpress.org/Transients_API

    And of course caching is important but I’ll assume you have that already!

  • This reply has been marked as private.
Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Does hard coding ACF fields increase speed of wordpress?’ is closed to new replies.