vendredi 15 janvier 2016

Wordpress: Cannot set ACF repeater field of a post after wp_insert_post

I'm now using WordPress Advanced Custom Fields Plugin: http://ift.tt/HaHFbk

And I set a repeater field rows on my custom post_type sales_order:

Then, now insert a post using script:

$post_id = wp_insert_post(array(
    'post_title' => $title,
    'post_name' => $slug,
    'post_content' => $content,
    'post_type' => 'sales_order',
    'post_status' => 'publish',
));

But when I do:

update_field('rows', array(), $post_id);

It has no effect.

But if I manually save the post in the admin panel first, then call the update_field method, it works.


So, I tried to spy the wp_postmeta database table, I found that if I call wp_insert_post using script, that post don't generate the meta

| meta_key | meta_value          |
|----------|---------------------|
| _rows    | field_568e7aeb22714 |

correctly.

But I have to do the import workflow using pure script, how can I work around this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire