Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling PHP Generated Configs instead of dynamic #72

Open
JamiesonRoberts opened this issue Nov 9, 2018 · 7 comments
Open

Handling PHP Generated Configs instead of dynamic #72

JamiesonRoberts opened this issue Nov 9, 2018 · 7 comments

Comments

@JamiesonRoberts
Copy link

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
Copy link

hi @JamiesonRoberts have you found a way around this?

@matthewsuan
Copy link

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
Copy link

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
Copy link
Author

@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
Copy link

tbruckmaier commented Jul 29, 2019

@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
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants