Home › Forums › General Issues › Documentation to create fields with php code › Reply To: Documentation to create fields with php code
“…I don’t want to create the field/group of fields inside the admin of a site and then export the code and copy/paste the piece of code in my plugin…”
I think that is basically what you need to do. I’ve created a few plugins that use ACF fields. You use the function register_field_group() …
Which I’m suddenly not finding any documentation on, I’m sure it used to be around here somewhere…
you call this function on the action hook “acf/register_fields”… which I’m also not finding any documentation on.
You could type out the array for the field group by hand, but it would be much easier to use ACF to create the fields and export the PHP code to copy into your plugin.
But in the documentation that I can’t find it outlined the steps.
add_action('acf/register_fields', 'my_register_fields_function');
function my_register_fields_function() {
if (function_exists('register_field_group')) {
// use the field group you export from ACF for $my_field_group
$my_field_group = array();
register_field_group($my_field_group);
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.