API Template Global Functions


目录

get_field()

This function will return a custom field value for a specific field name/key + post_id. There is a 3rd parameter to turn on/off formatting. This means that an image field will not use its 'return option' to format the value but return only what was saved in the database

the_field()

This function is the same as echo get_field(), but will escape the value for safe HTML output regardless of parameters.

_acf_log_escaped_html()

Logs instances of ACF successfully escaping unsafe HTML.

_acf_get_escaped_html_log()

Returns an array of instances where HTML was altered due to escaping in the_field or a shortcode.

_acf_update_escaped_html_log()

Updates the array of instances where HTML was altered due to escaping in the_field or a shortcode.

_acf_delete_escaped_html_log()

Deletes the array of instances where HTML was altered due to escaping in the_field or a shortcode. Since ACF 6.2.7, also clears the legacy acf_will_escape_html_log option to clean up.

get_field_object()

This function will return an array containing all the field data for a given field_name.

acf_maybe_get_field()

This function will return a field for the given selector. It will also review the field_reference to ensure the correct field is returned which makes it useful for the template API

acf_maybe_get_sub_field()

This function will attempt to find a sub field

get_fields()

This function will return an array containing all the custom field values for a specific post_id. The function is not very elegant and wastes a lot of PHP memory / SQL queries if you are not using all the values.

get_field_objects()

This function will return an array containing all the custom field objects for a specific post_id. The function is not very elegant and wastes a lot of PHP memory / SQL queries if you are not using all the fields / values.

have_rows()

Checks if a field (such as Repeater or Flexible Content) has any rows of data to loop over. This function is intended to be used in conjunction with the_row() to step through available values.

the_row()

This function will progress the global repeater or flexible content value 1 row

get_row_sub_field()

This function is used inside a 'has_sub_field' while loop to return a sub field object

get_row_sub_value()

This function is used inside a 'has_sub_field' while loop to return a sub field value

reset_rows()

This function will find the current loop and unset it from the global array. To be used when loop finishes or a break is used

has_sub_field()

This function is used inside a while loop to return either true or false (loop again or stop). When using a repeater or flexible content field, it will loop through the rows until there are none left or a break is detected

has_sub_fields()

Alias of has_sub_field

get_sub_field()

This function is used inside a 'has_sub_field' while loop to return a sub field value

the_sub_field()

This function is the same as echo get_sub_field(), but will escape the value for safe HTML output.

get_sub_field_object()

This function is used inside a 'has_sub_field' while loop to return a sub field object

get_row_layout()

This function will return a string representation of the current row layout within a 'have_rows' loop

acf_shortcode()

This function is used to add basic shortcode support for the ACF plugin eg. [acf field="heading" post_id="123" format_value="1"]

update_field()

This function will update a value in the database

update_sub_field()

This function will update a value of a sub field in the database

delete_field()

This function will remove a value from the database

delete_sub_field()

This function will delete a value of a sub field in the database

add_row()

This function will add a row of data to a field

add_sub_row()

This function will add a row of data to a field

update_row()

This function will update a row of data to a field

update_sub_row()

This function will add a row of data to a field

delete_row()

This function will delete a row of data from a field

delete_sub_row()

This function will add a row of data to a field

create_field()

Deprecated Functions



版本号 #2
由 壳壳虫 创建于 2026-08-29 14:50:46 UTC
由 壳壳虫 更新于 2026-08-29 14:50:46 UTC