Support

Account

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