AdvancedCustomFields / AdvancedCustomFields/acf
custom fields still accessible after wp_delete_post. Probably an ACF cache problem?
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
$post_id = 123;
$my_field = get_field('my_field', $post_id); // $my_field holds field value
wp_delete_post($post_id);
$my_field = get_field('my_field', $post_id); // $my_field still holds field value
I assume the value is deleted from DB, but I would expect $my_field to be false after calling get_field a second time, since the post no longer exists after wp_delete_post.
I realize this is probably due to caching, but it's not intuitive, and this turned out to be the cause of a hard to debug problem in my code. In my case I was deleting a post, assuming all meta-data would be removed as well.
Then I recreate the post with the same ID.
Next, I loop trough an array, that I use to update some repeater fields, or add them if they don't exist. But of course, this didn't work, because after calling the get_field function again I was still getting the values from the deleted post.
EDIT: when I use WP's native get_post_meta, everything works as expected.
$post_id = 123;
$my_field = get_post_meta($post_id, 'my_field', true); // $my_field holds field value
wp_delete_post($post_id);
$my_field = get_post_meta($post_id, 'my_field', true); // $my_field is false
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the PHP example using get_field and wp_delete_post, then compare the result with WordPress's native get_post_meta as shown in the issue. Trace the relevant ACF cache behavior and verify that get_field no longer returns the deleted value, including after recreating a post with the same ID.
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
- Mostly clear
- Newbie friendliness
- 35/100