### Complete Form Example Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/03_form_api.md An example demonstrating how to display and handle a complete ACF form, including fetching fields, rendering them, and saving the data. ```APIDOC ## Complete Form Example ### Description This example shows how to retrieve field group and fields, set up a form with `acf_form_data`, render each field, and handle the form submission using `acf_save_post`. ### Code ```php
'post', 'post_id' => $post_id, 'validation' => true )); ?>
``` ``` -------------------------------- ### Get Options by Prefix Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/05_metadata_api.md Retrieves all options that start with a given prefix. The prefix is removed from the keys in the returned array. Searches both public and hidden options using a database query. ```php function acf_get_option_meta( $prefix = '' ) ``` ```php // Get all options starting with 'theme_' $theme_options = acf_get_option_meta( 'theme' ); // Returns: array( 'color' => 'blue', 'font' => 'Arial' ) ``` -------------------------------- ### Check if ACF Pro is Installed (acf_is_pro) Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/08_configuration.md Use this function to verify if the ACF Pro version is installed and active. This allows for conditional execution of Pro-specific features. ```php function acf_is_pro() if ( acf_is_pro() ) { // Use Pro-only features } ``` -------------------------------- ### acf_get_option_meta Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/05_metadata_api.md Retrieves all options that start with a specified prefix, removing the prefix from the returned keys. ```APIDOC ## acf_get_option_meta ### Description Retrieves all options that start with a given prefix. ### Method `acf_get_option_meta( $prefix = '' )` ### Parameters #### Path Parameters - **$prefix** (string) - Optional - The option name prefix to search for. ### Returns `array` — Array of prefix_key => values. ### Example ```php // Get all options starting with 'theme_' $theme_options = acf_get_option_meta( 'theme' ); // Returns: array( 'color' => 'blue', 'font' => 'Arial' ) ``` ### Notes - Removes prefix from keys in returned array - Searches both public and hidden (prefixed with _) options - Uses database query instead of get_option ``` -------------------------------- ### Get, Format, and Update Field Values Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/INDEX.md Retrieve a field definition, get its value for a specific post ID, and then format it for display. Alternatively, use the `get_field` template function as a shortcut. This is for retrieving and preparing data. ```php $field = acf_get_field( 'field_name' ); $value = acf_get_value( $post_id, $field ); $formatted = acf_format_value( $value, $post_id, $field ); // Or the template function shortcut $value = get_field( 'field_name', $post_id ); ``` -------------------------------- ### Get Field Groups and Render Fields Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/INDEX.md Retrieve a field group by its key, get all fields associated with it, and then render each field with its corresponding value. This pattern is useful for displaying a set of fields within a group. ```php $group = acf_get_field_group( 'group_key' ); $fields = acf_get_fields( $group ); foreach ( $fields as $field ) { acf_render_field( $field, get_field( $field['name'], $post_id ), $post_id ); } ``` -------------------------------- ### Rendering a Form with Fields Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/00_START_HERE.md Provides a code example for iterating through fields of a field group and rendering them using ACF functions. ```APIDOC ## Rendering a Form ```php $fields = acf_get_fields( $group ); foreach ( $fields as $field ) { acf_render_field_label( $field ); acf_render_field( $field, get_field( $field['name'], $post_id ), $post_id ); } ``` ``` -------------------------------- ### Get, Validate, and Render Fields Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/INDEX.md Use these functions to retrieve field definitions, validate them, and render them with a value. Ensure fields are properly retrieved and validated before rendering. ```php $field = acf_get_field( 'field_key' ); $validated = acf_validate_field( $field ); acf_render_field( $field, $value, $post_id ); ``` -------------------------------- ### Template Functions Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/04_value_api.md Recommended template functions for getting, updating, and deleting field values. These are wrappers around core API functions. ```APIDOC ## Template Functions For most use cases, you'll use the simpler template functions instead: ```php // Get field value (recommended for templates) $value = get_field( 'field_name', $post_id ); // Update field value update_field( 'field_name', $value, $post_id ); // Delete field value delete_field( 'field_name', $post_id ); ``` These are wrappers around the core API functions that handle more logic automatically. ``` -------------------------------- ### Validating Before Save Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/00_START_HERE.md Implement a filter to intercept and potentially prevent the saving of field values. This example shows how to stop saving if a value is empty. ```php add_filter( 'acf/update_value', function( $value, $post_id, $field ) { if ( empty( $value ) ) { return false; // Prevent save } return $value; }, 10, 3 ); ``` -------------------------------- ### Get Taxonomy Definition Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/07_post_user_term_api.md Retrieves a specific taxonomy definition by its ID, key, or name. Returns false if the taxonomy is not found. ```php function acf_get_taxonomy( $id = 0 ) ``` -------------------------------- ### Complete Form Example Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/03_form_api.md Renders a complete ACF form for a given post ID, including fields, labels, instructions, and submission handling. Ensure to include acf_form_data for proper form processing. ```php
'post', 'post_id' => $post_id, 'validation' => true )); ?>
``` -------------------------------- ### acf_is_pro Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/08_configuration.md Determines if the ACF Pro version of the plugin is installed and activated. Essential for implementing Pro-specific features. ```APIDOC ## acf_is_pro ### Description Checks if ACF Pro is installed and activated. ### Signature ```php function acf_is_pro(): bool ``` ### Returns - **bool** - True if ACF Pro is active, false otherwise. ### Example ```php if ( acf_is_pro() ) { // Use Pro-only features } ``` ``` -------------------------------- ### ACF Function Parameter Table Example Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/README.md This table demonstrates the standard format for documenting function parameters in the ACF API reference. It includes details on parameter name, type, requirement, default value, and description. ```markdown | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | $id | int|string | No | 0 | The field ID or key. | ``` -------------------------------- ### Configure ACF Settings and Check Pro Version Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/INDEX.md Manage ACF settings using `acf_update_setting` and retrieve them with `acf_get_setting`. Check if the Pro version is installed using `acf_is_pro()` to conditionally use Pro features. This is for plugin configuration and feature detection. ```php // Check if pro is installed if ( acf_is_pro() ) { // Use pro features } // Configure settings acf_update_setting( 'google_api_key', 'YOUR_KEY' ); // Check plugin version $version = acf_get_setting( 'version' ); ``` -------------------------------- ### Metadata Operations Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/INDEX.md Functions for getting, updating, deleting, and copying metadata associated with objects. ```APIDOC ## Metadata Operations ### Get - `acf_get_meta( $object_id, $object_type = 'post' )` — Get all meta for object - `acf_get_metadata( $meta_id )` — Get single meta value - `acf_get_metadata_by_field( $field, $object_id, $object_type = 'post' )` — Get value using field - `acf_get_option_meta( $prefix, $option_name = '' )` — Get options by prefix - `acf_get_metaref( $field_name, $object_id, $object_type = 'post' )` — Get field key for name ### Update - `acf_update_metadata( $meta_id, $value, $object_id = 0, $object_type = 'post' )` — Update meta value - `acf_update_metadata_by_field( $field, $value, $object_id, $object_type = 'post' )` — Update using field - `acf_update_metaref( $field_name, $field_key, $object_id = 0, $object_type = 'post' )` — Map name to field key ### Delete - `acf_delete_metadata( $meta_id, $object_id = 0, $object_type = 'post' )` — Delete meta value - `acf_delete_metadata_by_field( $field, $object_id, $object_type = 'post' )` — Delete using field ### Copy - `acf_copy_metadata( $from_object_id, $to_object_id, $object_type = 'post' )` — Copy all meta between objects - `acf_copy_postmeta( $from_post_id, $to_post_id )` — Deprecated alias ### Helper - `acf_get_meta_field( $meta_name, $object_type = 'post' )` — Get field from meta name ``` -------------------------------- ### Get Available Post Templates Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/07_post_user_term_api.md Retrieves an array of available post templates for registered post types. Useful for dynamically populating template selection options. ```php function acf_get_post_templates() ``` ```php $templates = acf_get_post_templates(); // Returns: // array( // 'page' => array( // 'Template Name' => 'template-file.php' // ), // 'post' => array( // 'Post Template' => 'post-template.php' // ) // ) ``` -------------------------------- ### Get All Raw Field Groups Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/02_field_group_api.md Retrieves all raw field group data from the database. This function returns an array of all field group configurations. ```php function acf_get_raw_field_groups() ``` -------------------------------- ### Get Textarea Input HTML Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/03_form_api.md Generates and returns the HTML for a textarea element as a string. Use this when you need to capture the textarea HTML for later use. ```php function acf_get_textarea_input( $atts = array() ) ``` -------------------------------- ### Get Field Key Reference Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/05_metadata_api.md Retrieves the field key for a given field name and post ID. Returns null if the reference is not found. ```php function acf_get_metaref( $post_id = 0, $name = '' ) ``` ```php $field_key = acf_get_metaref( $post_id, 'my_field_name' ); ``` -------------------------------- ### Get Post Type Definition Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/07_post_user_term_api.md Retrieves a specific post type definition by its ID, key, or name. Returns false if the post type is not found. ```php function acf_get_post_type( $id = 0 ) ``` -------------------------------- ### Get All ACF Metadata for an Object Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/05_metadata_api.md Retrieves all ACF metadata for a given object ID. Supports posts, users, terms, and options by prefixing the ID. ```php // Get all meta for a post $meta = acf_get_meta( $post_id ); // Returns: array( 'field_name' => 'value', 'other_field' => 'value' ) // Get all meta for a user $user_meta = acf_get_meta( 'user_' . $user_id ); // Get all meta for a term $term_meta = acf_get_meta( 'term_' . $term_id ); // Get all meta for an option $option_meta = acf_get_meta( 'option_my_option_name' ); ``` -------------------------------- ### Location Rules Structure Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/02_field_group_api.md Explains the structure of location rules used to determine where field groups appear. Includes common location types and an example of the rule structure. ```APIDOC ## Location Rules Location rules determine where field groups appear in the WordPress admin. Common location types: - **post_type**: Specific post type (post, page, custom_post_type) - **post_template**: Specific page template - **post_status**: Draft, published, etc. - **user_role**: Specific user role - **user_form**: User profile, registration form, etc. - **taxonomy**: Specific taxonomy term - **attachment**: Media/attachment screens - **options_page**: ACF Options pages - **comment**: Comment edit screens **Location Rule Structure:** ```php $field_group['location'] = array( array( // First rule group (AND logic) array( 'param' => 'post_type', 'operator' => '==', 'value' => 'post' ), array( 'param' => 'post_template', 'operator' => '==', 'value' => 'my-template.php' ) ), array( // Second rule group (OR logic) array( 'param' => 'post_type', 'operator' => '==', 'value' => 'page' ) ) ); ``` ``` -------------------------------- ### Commonly Used ACF Functions Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/00_START_HERE.md This section provides quick examples of frequently used ACF functions for common tasks like retrieving field values, definitions, and rendering fields. ```APIDOC ## Common ACF Functions ### Get field value ```php $value = get_field( 'field_name', $post_id ); ``` ### Get field definition ```php $field = acf_get_field( 'field_key' ); ``` ### Get field group ```php $group = acf_get_field_group( 'group_key' ); ``` ### Get all fields in group ```php $fields = acf_get_fields( $group ); ``` ### Render field HTML ```php acf_render_field( $field, $value, $post_id ); ``` ### Save form data ```php acf_save_post( $post_id ); ``` ``` -------------------------------- ### Common ACF Operations in PHP Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/INDEX.md Provides examples for frequently used ACF functions to retrieve, update, and manage field values and definitions. Ensure the ACF plugin is active and field keys/names are correct. ```php // Get a field value from a post $value = get_field( 'field_name', $post_id ); ``` ```php // Update a field value update_field( 'field_name', 'new value', $post_id ); ``` ```php // Get a field definition $field = acf_get_field( 'field_key' ); ``` ```php // Get all fields in a field group $fields = acf_get_fields( 'group_key' ); ``` ```php // Get a field group $group = acf_get_field_group( 'group_key' ); ``` ```php // Render a field in a form acf_render_field( $field, get_field( 'field_name', $post_id ), $post_id ); ``` ```php // Save fields from form data acf_save_post( $post_id ); ``` -------------------------------- ### Get Metadata by Field Definition Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/05_metadata_api.md Retrieves a metadata value using a field definition array, which must include a 'name' key. Useful when you have the field object. ```php $field = acf_get_field( 'field_abc123' ); $value = acf_get_metadata_by_field( $post_id, $field ); ``` -------------------------------- ### Get All Filter States - PHP Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/06_helper_functions.md Retrieves the current states of all registered filters. Returns an associative array where keys are filter names and values are their states (enabled/disabled). ```php function acf_get_filters() ``` -------------------------------- ### Get Text Input HTML Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/03_form_api.md Generates and returns the HTML for a text input element as a string. This allows for programmatic control over the input's HTML before it's displayed. ```php function acf_get_text_input( $atts = array() ) ``` -------------------------------- ### Get Multiple Request Arguments with Defaults (PHP) Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/06_helper_functions.md Retrieve multiple values from the $_REQUEST superglobal, providing default values for each if they are not set. This is useful for safely accessing form or URL parameters. ```php function acf_request_args( $args = array() ) ``` ```php $args = acf_request_args( array( 'action' => 'default_action', 'post_id' => 0, 'field_key' => '' ) ); ``` -------------------------------- ### Get Field by ID, Key, or Name (PHP) Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/01_field_api.md Retrieves a field array using its ID, key, or name. Use this to access field properties like label and type. Ensure the field exists before accessing its properties. ```php // Get by ID $field = acf_get_field( 123 ); // Get by field key $field = acf_get_field( 'field_abc123def456' ); // Get by field name $field = acf_get_field( 'my_field_name' ); if ( $field ) { echo $field['label']; echo $field['type']; } ``` -------------------------------- ### Render Field Instructions - PHP Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/03_form_api.md Renders the instructions text for a given field if the 'instructions' key is present in the field array. ```php $field = acf_get_field( 'field_abc123' ); íciacf_render_field_instructions( $field ); ``` -------------------------------- ### Core Functions - Getting Field Values Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/README.md Core functions for retrieving and formatting field values. `acf_get_value()` retrieves the raw value, while `acf_format_value()` prepares it for display. ```APIDOC ## acf_get_value() ### Description Retrieves the raw value for a given field. ### Function Signature `acf_get_value( $post_id, $field )` ### Parameters - **$post_id** (int|string) - The ID of the post, user, term, or option to retrieve the value from. - **$field** (array) - The field array containing field settings. ## acf_format_value() ### Description Formats a field's value for display. ### Function Signature `acf_format_value( $value, $post_id, $field )` ### Parameters - **$value** (mixed) - The raw field value. - **$post_id** (int|string) - The ID of the post, user, term, or option. - **$field** (array) - The field array containing field settings. ``` -------------------------------- ### Get ACF Activation Version (acf_get_version_when_first_activated) Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/08_configuration.md Retrieves the version number of ACF when the plugin was initially activated. Useful for implementing upgrade-specific logic or tracking migration paths. ```php function acf_get_version_when_first_activated() $first_version = acf_get_version_when_first_activated(); if ( $first_version && version_compare( $first_version, '6.0.0', '<' ) ) { // This is an upgrade from v5 } ``` -------------------------------- ### Get Multibyte String Length Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/06_helper_functions.md Use `acf_strlen` to accurately get the length of a string, correctly handling multibyte characters. This is important for internationalization and accurate character counting. ```php function acf_strlen( $str = '' ) { // ... implementation details ... } ``` -------------------------------- ### Get ACF Field Key by Name Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/04_value_api.md Retrieves the field key for a given field name and post ID. This function is useful when you only have the field name and need to get the field object. ```php function acf_get_reference( $field_name, $post_id ) ``` ```php $field_key = acf_get_reference( 'my_field_name', $post_id ); $field = acf_get_field( $field_key ); ``` -------------------------------- ### Get Field Definition from Metadata Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/05_metadata_api.md Retrieves a field definition array using a metadata key and post ID. It uses a reference system to match the field name to a specific post. ```php function acf_get_meta_field( $key = 0, $post_id = 0 ) ``` ```php $field = acf_get_meta_field( 'my_field_name', $post_id ); if ( $field ) { echo $field['type']; // Get field type } ``` -------------------------------- ### Get and Display ACF Field Value Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/README.md Retrieve a field definition, get its value for a specific post ID, format it for display, and then echo the formatted value. Ensure the field key is correct. ```php $field = acf_get_field( 'field_key' ); $value = acf_get_value( $post_id, $field ); $formatted = acf_format_value( $value, $post_id, $field ); echo $formatted; ``` -------------------------------- ### Extend ACF with Hooks Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/README.md Illustrates how to extend ACF's functionality using WordPress filters. Examples include modifying field settings before loading, validating values before saving, and formatting values for display. These hooks allow for custom behavior without altering core plugin files. ```php // Modify a field after loading add_filter( 'acf/load_field/type=text', function( $field ) { $field['placeholder'] = 'Enter text here'; return $field; }); // Validate a value before saving add_filter( 'acf/update_value/name=my_field', function( $value, $post_id, $field ) { if ( empty( $value ) ) { return false; // Prevent save } return $value; }, 10, 3 ); // Format a value for display add_filter( 'acf/format_value/type=text', function( $value, $post_id, $field ) { return strtoupper( $value ); }, 10, 3 ); ``` -------------------------------- ### Get and Update Option Field Values Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/04_value_api.md Access and modify field values stored in WordPress options by using the 'option_' prefix followed by the option name. Useful for theme settings. ```php // Get option field value $value = acf_get_value( 'option_my_option_name', $field ); ``` ```php // Update option field value acf_update_value( 'value', 'option_my_option_name', $field ); ``` -------------------------------- ### Select Field Settings Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/09_types.md Configure a select field with choices, nullability, multiple selection, and placeholder. ```php array( 'type' => 'select', 'choices' => array( 'value1' => 'Label 1', 'value2' => 'Label 2' ), 'allow_null' => false, 'multiple' => false, 'ui' => false, 'ajax' => false, 'placeholder' => '' ); ``` -------------------------------- ### acf_render_field_instructions Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/03_form_api.md Renders the instructions text for a given field. This is typically displayed below the field input. ```APIDOC ## acf_render_field_instructions ### Description Renders the instructions text for a field. ### Method `function acf_render_field_instructions( $field )` ### Parameters #### Arguments - `$field` (array) - Required - Field array with 'instructions' key. ### Returns `void` — Outputs HTML directly. ### Output Renders `

` with instructions text if present. ### Example ```php $field = acf_get_field( 'field_abc123' ); íciacf_render_field_instructions( $field ); ``` ``` -------------------------------- ### Field Operations Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/INDEX.md Functions for getting, checking, modifying, rendering, and translating ACF fields. ```APIDOC ## Field Operations ### Get - `acf_get_field( $field_id )` — Get field by ID/key/name - `acf_get_raw_field( $field_id )` — Get unvalidated field - `acf_get_field_post( $field_id )` — Get field's WP_Post - `acf_get_fields( $post_id )` — Get fields for field group - `acf_get_raw_fields( $post_id )` — Get raw field array - `acf_get_field_count( $post_id )` — Count fields in group ### Check/Validate - `acf_is_field( $field )` — Check if value is field array - `acf_is_field_key( $key )` — Check if string is field key - `acf_validate_field( $field )` — Validate field structure - `acf_get_valid_field( $field )` — Alias for validate ### Modify - `acf_update_field( $field )` — Update field in database - `acf_delete_field( $field_id )` — Delete field - `acf_trash_field( $field_id )` — Move to trash - `acf_untrash_field( $field_id )` — Restore from trash - `acf_clone_field( $field, $parent = false )` — Clone field (internal) - `acf_duplicate_field( $field_id )` — Duplicate field - `acf_duplicate_fields( $field_ids )` — Duplicate multiple fields - `acf_prefix_fields( $fields, $prefix )` — Add prefix to field names - `acf_prepare_field_for_export( $field )` — Prepare export ### Render - `acf_render_field( $field )` — Render field HTML - `acf_render_field_wrap( $field )` — Render field wrapper - `acf_render_field_label( $field )` — Render label - `acf_render_field_instructions( $field )` — Render instructions - `acf_render_field_setting( $field, $key, $value )` — Render field setting UI ### Translation - `acf_translate_field( $field )` — Translate field strings ``` -------------------------------- ### Retrieve Data from ACF Global Store Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/08_configuration.md Use `acf_get_data` to retrieve stored data. Provide a key to fetch specific data, or leave it empty to get all stored data. A default value can be specified if the key is not found. ```php acf_get_data( 'post_templates' ); ``` -------------------------------- ### Text Field Settings Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/09_types.md Configure a text field with options like placeholder, max length, and prefixes. ```php array( 'type' => 'text', 'placeholder' => '', 'maxlength' => '', 'prepend' => '', 'append' => '' ); ``` -------------------------------- ### Get ACF Field Group Title Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/02_field_group_api.md Retrieves the display title for a given ACF field group array. ```php function acf_get_field_group_title( $field_group ) ``` -------------------------------- ### Working with Different Object Types Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/00_START_HERE.md Demonstrates how to use `acf_get_value` to retrieve field values from various object types including posts, users, terms, and options. ```APIDOC ## Working with Different Object Types ### Get post value ```php $post_value = acf_get_value( $post_id, $field ); ``` ### Get user value ```php $user_value = acf_get_value( 'user_' . $user_id, $field ); ``` ### Get term value ```php $term_value = acf_get_value( 'term_' . $term_id, $field ); ``` ### Get option value ```php $option_value = acf_get_value( 'option_my_option', $field ); ``` ``` -------------------------------- ### Get Fields for a Field Group (PHP) Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/01_field_api.md Retrieves an array of all fields belonging to a specific field group. You can pass the field group's ID, key, name, or the field group array itself. Returns an empty array if no fields are found. ```php // Get field group and its fields $field_group = acf_get_field_group( 'my_field_group' ); $fields = acf_get_fields( $field_group ); foreach ( $fields as $field ) { echo $field['label'] . ': ' . $field['type']; } // Or pass field group ID directly $fields = acf_get_fields( 123 ); ``` -------------------------------- ### Get All Taxonomies Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/07_post_user_term_api.md Retrieves all registered ACF taxonomies, optionally filtered by specific arguments. Useful for iterating through available taxonomies. ```php function acf_get_taxonomies( $filter = array() ) ``` ```php $taxonomies = acf_get_taxonomies(); foreach ( $taxonomies as $taxonomy ) { echo $taxonomy['name']; echo $taxonomy['label']; } ``` -------------------------------- ### Number Field Settings Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/09_types.md Configure a number field with options for placeholder, min/max values, and step increment. ```php array( 'type' => 'number', 'placeholder' => '', 'min' => '', 'max' => '', 'step' => '' ); ``` -------------------------------- ### Working with Different Object Types Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/00_START_HERE.md Demonstrates how to retrieve ACF field values from various object types including posts, users, terms, and options using a consistent function. ```php $post_value = acf_get_value( $post_id, $field ); $user_value = acf_get_value( 'user_' . $user_id, $field ); $term_value = acf_get_value( 'term_' . $term_id, $field ); $option_value = acf_get_value( 'option_my_option', $field ); ``` -------------------------------- ### Get ACF Setting Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/08_configuration.md Retrieve the value of a specific ACF setting. Provide a default value to be returned if the setting is not found. ```php function acf_get_setting( $key = '', $default = null ) ``` ```php $google_key = acf_get_setting( 'google_api_key' ); $version = acf_get_setting( 'version' ); $uploader = acf_get_setting( 'uploader', 'wp' ); ``` -------------------------------- ### Configuration and State Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/INDEX.md Functions for accessing and modifying ACF settings, stores, global data, and checking system state. ```APIDOC ## Configuration and State ### Description Functions for managing ACF settings, data stores, and system state. ### Settings - `acf_get_setting()`: Retrieve the value of an ACF setting. - `acf_update_setting()`: Update an ACF setting. Settings control version, capabilities, UI options, API keys, file paths, REST API, and localization. ### Stores - `acf_register_store()`: Create a new cache store. - `acf_get_store()`: Access a store for reading and writing data. ### Data - `acf_get_data()`: Retrieve global ACF data. - `acf_set_data()`: Set global ACF data. ### State - `acf_did()`: Check if a specific action has been fired. - `acf_doing_action()`: Check if an action is currently being executed. - `acf_is_pro()`: Determine if the ACF Pro version is installed. - `acf_is_beta()`: Check if the beta version of ACF is active. - `acf_get_version_when_first_activated()`: Retrieve the version number of ACF when it was first activated. ``` -------------------------------- ### Get a validated field array - PHP Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/01_field_api.md An alias for `acf_validate_field()`. Use this to ensure a field array is valid and has default values applied. ```php function acf_get_valid_field( $field = false ) ``` -------------------------------- ### Enable Filters and Save State - PHP Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/06_helper_functions.md Enables all filters or a specified subset, returning the previous filter states. This is useful for temporarily disabling filters and then restoring their original state. ```php function acf_enable_filters( $filters = array() ) ``` ```php // Disable filters, save state $prev_state = acf_disable_filters(); // Do something with filters disabled // ... // Restore previous state afcf_enable_filters( $prev_state ); ``` -------------------------------- ### Textarea Field Settings Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/09_types.md Configure a textarea field with placeholder, max length, and row count. ```php array( 'type' => 'textarea', 'placeholder' => '', 'maxlength' => '', 'rows' => 4 ); ``` -------------------------------- ### Get Radio Button HTML Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/03_form_api.md Retrieves the HTML string for radio button input elements. This is useful if you need to process the HTML before outputting it. ```php function acf_get_radio_input( $atts = array() ) ``` -------------------------------- ### Get Object ID from Post ID using ACF Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/07_post_user_term_api.md Extracts the numeric or string ID from a post ID, regardless of its type prefix. ```php function acf_get_object_id( $post_id = 0 ) ``` -------------------------------- ### General Utilities Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/INDEX.md Miscellaneous utility functions for generating IDs, merging attributes, caching, and request handling. ```APIDOC ## General Utilities ### Description Various utility functions for common tasks. ### Functions - `acf_uniqid()`: Generate a unique ID. - `acf_merge_attributes()`: Merge HTML attributes intelligently. - `acf_cache_key()`: Get or filter a cache key. - `acf_decode_post_id()`: Split a post ID into its type and ID components. - `acf_request_args()`: Get values from the $_REQUEST superglobal with defaults. - `acf_request_arg()`: Get a single value from the $_REQUEST superglobal. ``` -------------------------------- ### acf_get_store Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/08_configuration.md Retrieves a previously registered data store by its name. This allows access to the store's methods for getting or setting cached data. ```APIDOC ## acf_get_store ### Description Retrieves a registered store. ### Signature ```php function acf_get_store( string $name = '' ): ACF_Data ``` ### Parameters #### Path Parameters - **$name** (string) - Optional - Store name. ### Returns `ACF_Data` — The store object. ### Request Example ```php $store = acf_get_store( 'fields' ); $field = $store->get( 'field_abc123' ); ``` ``` -------------------------------- ### Get All Fields in Group Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/00_START_HERE.md Retrieve an array of all field definitions associated with a specific field group. This is useful for iterating over fields within a group. ```php // Get all fields in group $fields = acf_get_fields( $group ); ``` -------------------------------- ### Import Taxonomy Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/07_post_user_term_api.md Imports a taxonomy definition from an array or export data. Requires the taxonomy array to be imported. ```php function acf_import_taxonomy( $taxonomy ) ``` -------------------------------- ### Update User Capability for ACF Management Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/08_configuration.md Use this function to change the capability required to manage ACF settings. For example, restrict management to editors. ```php acf_update_setting( 'capability', 'edit_others_posts' ); ``` -------------------------------- ### Set Filter States - PHP Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/06_helper_functions.md Sets the states for multiple filters at once. Accepts an array where keys are filter names and values are their desired states. ```php function acf_set_filters( $filters = array() ) ``` -------------------------------- ### acf_get_version_when_first_activated Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/08_configuration.md Retrieves the version number of ACF that was active when the plugin was first installed and activated. Useful for tracking upgrade paths and implementing backward compatibility. ```APIDOC ## acf_get_version_when_first_activated ### Description Gets the ACF version when the plugin was first activated. ### Signature ```php function acf_get_version_when_first_activated(): ?string ``` ### Returns - **string | null** - The version string (e.g., '5.10.0') if the plugin has been activated before, or null if it has never been activated. ### Useful for Conditional logic based on upgrade path. ### Example ```php $first_version = acf_get_version_when_first_activated(); if ( $first_version && version_compare( $first_version, '6.0.0', '<' ) ) { // This is an upgrade from v5 } ``` ``` -------------------------------- ### Get Select Input HTML Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/03_form_api.md Retrieves the HTML string for a select input element. Use this when you need the HTML output to manipulate or display elsewhere. ```php function acf_get_select_input( $atts = array() ) ``` -------------------------------- ### Configure Local JSON Storage Paths Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/08_configuration.md Specify directories for saving and loading ACF field group JSON files. This allows for version control and easier deployment of field configurations. ```php acf_update_setting( 'save_json', get_stylesheet_directory() . '/acf-json' ); íciacf_update_setting( 'load_json', array( get_stylesheet_directory() . '/acf-json', get_template_directory() . '/acf-json' ) ); ``` -------------------------------- ### Configuration and Settings Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/README.md Functions for interacting with ACF's configuration. `acf_update_setting()` allows modification of plugin settings. ```APIDOC ## acf_update_setting() ### Description Updates a specific ACF setting. ### Function Signature `acf_update_setting( $name, $value )` ### Parameters - **$name** (string) - The name of the setting to update. - **$value** (mixed) - The new value for the setting. ``` -------------------------------- ### Get Checkbox Input HTML Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/03_form_api.md Generates and returns the HTML for a checkbox input element as a string. This is useful when you need to manipulate or store the HTML before outputting it. ```php function acf_get_checkbox_input( $atts = array() ) ``` -------------------------------- ### Get a Specific Field Group Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/02_field_group_api.md Retrieves a field group by its ID, key, or name. Use this to access a single field group's configuration. ```php function acf_get_field_group( $id = 0 ) ``` ```php $group = acf_get_field_group( 'group_abc123def456' ); if ( $group ) { echo $group['title']; echo $group['active'] ? 'Active' : 'Inactive'; } ``` -------------------------------- ### Pre-load Metadata Filter Hook Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/05_metadata_api.md This filter hook allows short-circuiting the metadata loading process. Return a non-null value to bypass normal loading. ```php apply_filters( 'acf/pre_load_meta', null, $post_id ) ``` -------------------------------- ### Pre-load Single Metadata Filter Hook Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/05_metadata_api.md Use this filter hook to short-circuit the loading of a single piece of metadata. It allows for custom logic before a specific meta field is retrieved. ```php apply_filters( 'acf/pre_load_metadata', null, $post_id, $name, $hidden ) ``` -------------------------------- ### Get Specific Metadata Value Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/05_metadata_api.md Retrieves a specific metadata value by its name. Can also retrieve hidden metadata by setting the $hidden parameter to true. ```php // Get public metadata $value = acf_get_metadata( $post_id, 'my_field_name' ); // Get hidden metadata (prefixed with underscore) $hidden_value = acf_get_metadata( $post_id, 'my_field_name', true ); ``` -------------------------------- ### Translate field label and instructions - PHP Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/01_field_api.md Translates the `label` and `instructions` properties of a field array based on active locale settings. Translation only occurs if the `l10n` setting is enabled and `l10n_textdomain` is configured. ```php function acf_translate_field( $field = array() ) ``` -------------------------------- ### String Utilities Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/INDEX.md Functions for manipulating strings, such as converting to IDs, slugs, or adding punctuation. ```APIDOC ## String Utilities ### Description Utility functions for string manipulation. ### Functions - `acf_idify()`: Convert a string to an ID-safe format. - `acf_slugify()`: Convert a string to a URL slug. - `acf_punctify()`: Add punctuation to a string. - `acf_strlen()`: Get the length of a string. ``` -------------------------------- ### Get Field Group Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/00_START_HERE.md Retrieve the definition array for a field group using its unique key. This allows access to group settings and associated fields. ```php // Get field group $group = acf_get_field_group( 'group_key' ); ``` -------------------------------- ### Form Operations Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/INDEX.md Functions for setting up, saving, and rendering ACF forms and inputs. ```APIDOC ## Form Operations ### Form Setup - `acf_form_data()` — Output form meta and nonces - `acf_set_form_data( $form_data )` — Store form data - `acf_get_form_data()` — Retrieve form data ### Save - `acf_save_post( $post_id )` — Save form field values - `_acf_do_save_post( $post_id )` — Internal save handler ### Rendering - `acf_render_field( $field )` — Render field input - `acf_render_field_wrap( $field )` — Render wrapper - `acf_render_field_label( $field )` — Render label - `acf_render_field_instructions( $field )` — Render instructions - `acf_render_fields( $fields, $post_id, $form )` — Render multiple fields ### Inputs - `acf_text_input( $field )` / `acf_get_text_input( $field )` - `acf_textarea_input( $field )` / `acf_get_textarea_input( $field )` - `acf_checkbox_input( $field )` / `acf_get_checkbox_input( $field )` - `acf_select_input( $field )` / `acf_get_select_input( $field )` - `acf_radio_input( $field )` / `acf_get_radio_input( $field )` - `acf_hidden_input( $field )` / `acf_get_hidden_input( $field )` - `acf_file_input( $field )` / `acf_get_file_input( $field )` ``` -------------------------------- ### Get Field Definition Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/00_START_HERE.md Retrieve the full definition array for a custom field using its unique key. This is useful for accessing field settings and metadata. ```php // Get field definition $field = acf_get_field( 'field_key' ); ``` -------------------------------- ### Configure Google Maps API Key Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/08_configuration.md Set the Google API key required for ACF's map and geocoding features. Ensure the key is valid and has the necessary permissions. ```php acf_update_setting( 'google_api_key', 'AIzaSyABC123DEF456...' ); ``` -------------------------------- ### Get Valid Field Group (Alias) Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/02_field_group_api.md An alias for the `acf_validate_field_group()` function. Use this when you need to ensure a field group array is valid and has default values applied. ```php function acf_get_valid_field_group( $field_group = false ) ``` -------------------------------- ### Get Field Group Post Object Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/02_field_group_api.md Retrieves the WP_Post object associated with a field group. Field groups are stored as the 'acf-field-group' custom post type. ```php function acf_get_field_group_post( $id = 0 ) ``` -------------------------------- ### Configure ACF Settings via Filter Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/08_configuration.md Use the 'acf/settings' filter in a must-use plugin to dynamically set ACF configurations like Google API keys and JSON save paths. This method is applied before ACF loads. ```php 'repeater', 'sub_fields' => array( array( 'key' => 'field_child', 'name' => 'child_field', 'type' => 'text', // ... field settings ) ), 'min' => 0, 'max' => 0, // 0 = unlimited 'collapsed' => '', 'button_label' => 'Add Row' ); ``` -------------------------------- ### Type Checking Utilities Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/INDEX.md Helper functions for checking the type or emptiness of values. ```APIDOC ## Type Checking Utilities ### Description Helper functions for validating data types and emptiness. ### Functions - `acf_is_empty()`: Check if a value is empty (allows 0). - `acf_not_empty()`: Check if a value is not empty (allows 0). - `acf_is_field()`: Check if a value is a field array. - `acf_is_field_group()`: Check if a value is a field group array. - `acf_is_post_type()`: Check if a value is a post type. ``` -------------------------------- ### Get, Update, and Delete Field Values Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/04_value_api.md Use these template functions for common operations on ACF field values. They are recommended for use within theme templates. ```php // Get field value (recommended for templates) $value = get_field( 'field_name', $post_id ); ``` ```php // Update field value update_field( 'field_name', $value, $post_id ); ``` ```php // Delete field value delete_field( 'field_name', $post_id ); ``` -------------------------------- ### Duplicate a field - PHP Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/01_field_api.md Creates a new field that is a duplicate of an existing field, preserving most of its settings. Returns the newly created duplicate field array. ```php function acf_duplicate_field( $field ) ``` -------------------------------- ### Get Field Value Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/00_START_HERE.md Retrieve the value of a specific custom field for a given post ID. This is a common template function for displaying ACF field data. ```php // Get field value $value = get_field( 'field_name', $post_id ); ``` -------------------------------- ### Validate ACF Field Key String Source: https://github.com/advancedcustomfields/acf/blob/master/_autodocs/06_helper_functions.md Use `acf_is_field_key` to check if a string conforms to the ACF field key format. It verifies if the string starts with 'field_'. ```php function acf_is_field_key( $id = '' ) { // Implementation details omitted for brevity } ```