corcel / acf

Advanced Custom Fields (ACF) plugin for Corcel
126 stars 98 forks source link

Handling PHP Generated Configs instead of dynamic #72

Open JamiesonRoberts opened 5 years ago

JamiesonRoberts commented 5 years ago

Myself and another developer have been bashing our heads against this code for the past day, and its due to how ACF under the hood handles post meta when the options are exported as PHP instead of being driven by the database and you are reading it in.

We work on a team of several devs and having to pass around configurations is incredibly frustration and also means we can't deal with things like programmatic updates for releasing via deployment tools.

The crux of it comes down to the following. When you generate the PHP options and load them via functions.php and ACF reads them in, ACF no longer creates posts in the wp_posts table, and exclusively creates them as post meta because it knows the mapping. Leveraging this configuration would be a huge performance boost for corcel as well as make for a far more ideal scenario for multi-developer projects.

Any ideas on how that could be accomplished?

matthewsuan commented 5 years ago

hi @JamiesonRoberts have you found a way around this?

matthewsuan commented 5 years ago

for anyone stumbling into this, you need to access acf field via the field type accessor method.

instead of

$post->acf->field_name

you can do it via

$post->acf->{fieldType}('field_name')
so ...
$post->acf->boolean('enabled_something')
$post->acf->number('numeric_field')
tbruckmaier commented 5 years ago

I have been using https://github.com/superhuit-ch/wp-cli-acf-json for automatic syncs of the generated acf-json. The generated acf-json files are in git and whenever someone checks out the repository, they run wp acf-json sync and there database gets updated. Probably this can be automated by putting it into a git hook.

JamiesonRoberts commented 5 years ago

@tbruckmaier definitely cool, though the main concern I have with this and the whole point of saving out the configs into PHP files rather than database driven is that it cuts down the number of queries required to generate the page. This makes TTFB faster overall, especially when you are dealing with complex systems. The JSON files are great for portability of updating configuration, but including configurations via the functions files is better for performance.

tbruckmaier commented 5 years ago

@JamiesonRoberts yeah that's right, I ran into the same performance issues. You might want to check out my fork, I reworked the data fetching logic and it decreases the number of queries a lot (it takes the acf data directly from the post's meta data which is preloaded anyway).

rossjcooper commented 4 years ago

We are having the same issue, especially when trying to load in repeaters, the issue lies within the src/FieldFactory.php file, like you said it looks for the type in the DB but as it is configured in PHP it cannot find the sub-field types in the database so it always returns null

tbruckmaier commented 3 years ago

Meanwhile I have updated my fork to work with a php-generated config too: https://github.com/tbruckmaier/corcel-acf