ACF update_field() Function: Examples [Guide]

ACF update_field() function illustration: pencil editing a field card

Updating a custom field from PHP usually means a counter goes up, a status changes, or a form saves new data. The ACF update_field() function does that in one call, so you never write to wp_postmeta by hand.

This guide covers the three parameters, the post ID formats, and what the return value tells you. To read the saved value back, see the get_field guide.

Function Syntax

The function takes a selector, the new value, and an optional object ID:

<?php
update_field( $selector, $value, $post_id );
  • $selector is the field name or field key.
  • $value is the new value, in the format the field stores.
  • $post_id is optional. It defaults to the current post and accepts the formats listed below.

Update a Field

This example increments a view counter stored in a field named views:

<?php
$post_id = get_the_ID();
$views   = (int) get_field( 'views', $post_id );

update_field( 'views', $views + 1, $post_id );

Use the field key instead of the name when you can. A key such as field_5f2a1b keeps working if someone renames the field.

Post ID Formats

The third argument tells ACF where to save the value:

  • Post or page: a post ID, such as 123.
  • User: 'user_5', where 5 is the user ID.
  • Taxonomy term: 'category_4', using the taxonomy slug and term ID.
  • Options page: 'options'.

Return Value

The return value depends on what happened:

  • true when the stored value changed.
  • false when the new value matches the stored value.
  • A meta ID when ACF creates a new meta row for a non-option value.

Tip: false is not an error. It means the stored value already matches the new one, so no write happened.

FAQs About ACF update_field()

Does update_field() Work on the Front End?

Yes. It works anywhere WordPress runs PHP. Because it writes data, call it only after a capability and nonce check when the input comes from a visitor.

Why Does update_field() Return False?

The new value matches the stored value, so ACF skips the write. If you expected a change, check the field name and the post ID.

Can I Update a User Field?

Yes. Pass 'user_' . $user_id as the third argument, for example update_field( 'phone', $phone, 'user_' . $user_id );.

Conclusion

update_field() covers most write operations in ACF with one call, a clear return value, and support for posts, users, terms, and options. Pair it with get_field() to read the value back.

Related ACF guides:

Need a custom theme or ACF setup? Hire a WordPress developer, or reach out to me directly.

About The Author

Picture of Andriy Haydash

Andriy Haydash

Andriy Haydash is a WordPress Expert who helps people build and launch successful WordPress membership and e-learning websites.

Note: Not all of the articles are written directly by me.
Affiliate Disclaimer: Some links in the post may be my affiliate links

Kinsta - Managed Hosting for WordPress

Before YOU Leave...
Join My Newsletter

Get practical tips & tricks on how to start, grow and market your course/membership site.