AdvancedCustomFields / AdvancedCustomFields/acf

can't get update_field and get_fields to work

Open
#324 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
945
Forks
197
PR merge metrics
No merged PRs in 30d

Description

Hi, i am creating a post and inserting the acf fields programmatically. I can't get the get_fields function or update_fields function to work as they usually do.

update_fields() returns a number and get_fields() returns nothing

here is some example code

// Create new post.
$post_data = array(
	'post_title'    => 'My post',
	'post_type'     => 'post',
	'post_status'   => 'publish'
);
$post_id = wp_insert_post($post_data);

// Save a basic text value.
$field_key = "field_123456";
$value = "some new string";
// update_field($field_key, $value, $post_id);

$update = update_field($field_key, $value, $post_id);

$fields = get_fields($post_id);

echo $update; // returns - 9215

echo $fields; // returns blank

any help would be much appreciated.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example in issue #324 with wp_insert_post(), update_field(), and get_fields(). Read the ACF documentation and the implementation of these functions to determine why the reported return values occur. Done means identifying the cause and documenting or verifying the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.