Advanced Custom Fields (ACF) is a popular WordPress plugin that allows developers to easily create custom fields for different areas of the WordPress admin area. With ACF, you can add custom data fields for posts, pages, custom post types, taxonomies, and user profiles, all through an intuitive and user-friendly interface.
One of the biggest benefits of using ACF is its flexibility. It provides a wide range of field types, such as text, image, file, select, and many more, which enables developers to add any kind of custom field they need. Additionally, it offers a wide range of options for customizing the fields' appearance and behavior, such as label, instructions, required, and many more, which can be set on a per-field basis.
Another great feature of ACF is its support for custom field groups, which allow developers to organize their fields into logical groups, making it easy to find the fields they need and to create custom fields with multiple sections, fields or sub fields.
ACF also provides a wide range of advanced features such as the ability to create custom fields for options pages, media uploader and image cropping, repeater and flexible fields, and many more. These features enable developers to create complex and sophisticated custom fields, which can be used for a wide range of purposes.
Overall, Advanced Custom Fields is a powerful and flexible plugin that is essential for any WordPress developer looking to add custom fields to their website. With its intuitive interface, wide range of field types, and advanced features, ACF makes it easy to add custom data fields to your website, giving you more control over its functionality and making it more user-friendly for your clients.
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_5d3f9f9f9f9f9',
'title' => 'Product',
'fields' => array(
array(
'key' => 'field_5d3f9f9f9f9f9',
'label' => 'SKU',
'name' => 'sku',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
array(
'key' => 'field_5d3f9f9f9f9fa',
'label' => 'Price',
'name' => 'price',
'type' => 'number',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'min' => '',
'max' => '',
'step' => '',
),
array(
'key' => 'field_5d3f9f9f9f9fb',
'label' => 'Enable Sale Price',
'name' => 'enable_sale_price',
'type' => 'checkbox',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array(
'yes' => 'Yes',
),
'allow_custom' => 0,
'default_value' => array(
),
'layout' => 'vertical',
'toggle' => 0,
'return_format' => 'value',
'save_custom' => 0,
),
array(
'key' => 'field_5d3f9f9f9f9fc',
'label' => 'Sale Price',
'name' => 'sale_price',
'type' => 'number',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5d3f9f9f9f9fb',
'operator' => '==',
'value' => 'yes',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'min' => '',
'max' => '',
'step' => '',
),
array(
'key' => 'field_5d3f9f9f9f9fd',
'label' => 'Enable Stock Management',
'name' => 'enable_stock_management',
'type' => 'checkbox',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array(
'yes' => 'Yes',
),
'allow_custom' => 0,
'default_value' => array(
),
'layout' => 'vertical',
'toggle' => 0,
'return_format' => 'value',
'save_custom' => 0,
),
array(
'key' => 'field_5d3f9f9f9f9fe',
'label' => 'Stock',
'name' => 'stock',
'type' => 'number',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5d3f9f9f9f9fd',
'operator' => '==',
'value' => 'yes',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'min' => '',
'max' => '',
'step' => '',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'product',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
endif;
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_1',
'title' => 'My Group',
'fields' => array (
array (
'key' => 'field_1',
'label' => 'Select Pages',
'name' => 'select_pages',
'type' => 'select',
'multiple' => 1,
'choices' => cwpai_get_pages(),
)
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
),
),
));
endif;
// Get all pages
function cwpai_get_pages() {
$pages = get_pages();
$choices = array();
foreach ($pages as $page) {
$choices[$page->ID] = $page->post_title;
}
return $choices;
}