Home › Forums › Backend Issues (wp-admin) › Distributing ACF in a free plugin
Hello
I’m currently writing a free plugin using ACF free (4.4.12 from WP Repo)
I followed https://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/?version=4#instructions and I can create fields but my PHP register Fields doesn’t work: if(function_exists("register_field_group"))
return false…
ANy idea please?
Why not using acf_add_local_field_group
? (Check here and here)
Unfortunately the same, I don’t succed to go through tje ‘if’ :-/
The function may not exist when you are trying to create your fields. When are you trying to create the field group? Is your code inside an action filter?
The best time to do this in on “init” with a priority that will fire after ACF
add_action('init', 'register_my_post_groups', 20);
Thanks for your reply but unfortunately not work
If I ‘die’ just befor thee function_exists()
, it dies… but I never go through :-/
<?php
if ( ! defined( 'ABSPATH' ) ){ exit; } // Exit if accessed directly
function wpcasama_create_acf_field() {
if ( function_exists( "acf_add_local_field_group" ) ) {
acf_add_local_field_group( array(
'id' => 'acf_mail-alert',
'title' => 'Mail Alert',
'fields' => array(
array(
'key' => 'field_5ac3bb4effff5',
'label' => 'Phone',
'name' => 'wpcasama_phone',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'none',
'maxlength' => '',
),
array(
'key' => 'field_5ac3bb9adb144',
'label' => 'city',
'name' => 'wpcasama_city',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array(
'key' => 'field_5ac3bbc9db145',
'label' => 'Minimum Price',
'name' => 'wpcasama_min_price',
'type' => 'number',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'min' => 0,
'max' => '',
'step' => 1,
),
array(
'key' => 'field_5ac3bbf8db146',
'label' => 'Maximum Price',
'name' => 'maximum_price',
'type' => 'number',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'min' => 0,
'max' => '',
'step' => 1,
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'wpcasa-mail-alerte',
'order_no' => 0,
'group_no' => 0,
),
),
),
'options' => array(
'position' => 'normal',
'layout' => 'no_box',
'hide_on_screen' => array(),
),
'menu_order' => 0,
) );
}
}
add_action('init', 'wpcasama_create_acf_field', 200);
You must be logged in to reply to this topic.
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!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.