i have question about update_field after creating a post by code (importing from xlsx)
I have some acf fields (users and taxonomies) in a custom post type “match”, so i have winners, loosers, and a multiple taxonomy select
i create post like this
$postarr = array( 'post_title' => sanitize_text_field( wp_unslash( $titolo_post ) ), 'post_status' => "publish", 'post_type' => "fight", ); $post_id = wp_insert_post( $postarr);
and then i try to update fields
where $id_titoli is an array with taxonomy ids, and $lista_vincitori is array with users ids
In the backend, if i enter in the post, i see all fields correctly, but quering posts there is something that is wrong BUT it is fixed if i save post (witout modify any field) from backend….just like saving updates something…. what i’m doing wrong?
I have a feeling its due to how the data is inserted. Something in my head tells me that you need change the priority on the save post function when inserting data from an import.
I assume the post is created when you import from your XLS?
What does your function look like to import and add the ACF fields?
Check the docs as I think you need to amend the priority on the function. You may need to use the field key rather than the field name but think its the priority.
i fixed in this way
..... $id_titoli = "$term_id"; // before was $id_titoli = $term_id; ===>>> the error was here ....... $postarr = array( 'post_title' => sanitize_text_field( wp_unslash( $titolo_post ) ), 'post_status' => "publish", 'post_type' => "fight", ); $post_id = wp_insert_post( $postarr); ....... update_field(“match_valevole_per_titolo”,$id_titoli,$post_id);
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.