Home › Forums › Add-ons › Flexible Content Field › conditional in generated php code › Reply To: conditional in generated php code
@jochem You shouldn’t apply logic while building an array.
You might try:
$layouts = array();
if( in_array( 'service', $cpt_selection ) ) {
$layouts[] = array(
'id' => '',
'key' => '',
'
);
}
acf_add_local_field_group( array(
'key' => 'unique-key',
'title' => __('Content', 'textdomain'),
'fields' => array(
array(
'key' => 'unique-key',
'label' => __('Content', 'textdomain'),
'name' => 'field-name',
'type' => 'flexible_content',
'button_label' => __( 'Add content', 'textdomain' ),
'layouts' => $layouts,
)
),
'location' => array(),
'menu_order' => 10,
'position' => 'normal',
'style' => 'seamless',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => ''
) );
Hope this helps
Kind regards
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.