How is clicking ‘update’ on a post different from programatically creating posts?

hoping for some advice.

I’m programmatically inserting a large number of posts into wordpress from a JSON feed. The wp_insert_post function is working brilliantly and the posts are created, along with correctly populated Advanced Custom Fields meta data.

Read More

We have a strange issue by which until we manually click “update” on a single post the custom fields aren’t available using a JSON API plugin.

I’ve tried updating all via the bulk editor, as well as calling wp_update_post after the JSON import. It’s as if the act of clicking “update” on a single post saves the post in a different fashion.

Can anyone advise why this would be the case? Any advice or pointing in the right direction would be greatly appreciated!


EDIT: the code we’re using to update our post meta…

function __update_post_meta( $post_id, $field_name, $value = '' ) {
        if ( empty( $value ) OR ! $value )
        {
                delete_post_meta( $post_id, $field_name );
        }
        elseif ( ! get_post_meta( $post_id, $field_name ) )
        {
                add_post_meta( $post_id, $field_name, $value );
        }
        else
        {
                update_post_meta( $post_id, $field_name, $value );
        }
}

Related posts

Leave a Reply

1 comment

  1. So we resolved the particular issue we were having.

    When a post is programmatically created with ACF fields, the posts are not labelled in the same way as standard post meta. Read here for more info on that!

    Updating a post manually creates the necessary “aliases”. Until that point, if you want to get the info out, you need to reference ACF’s initial “fieldXXXXXXXX” post meta key.