如何以编程方式将已填充Advanced Custom Fields的新帖子创建并插入数据库?
答案 0 :(得分:5)
假设您有一个ACF组,其中包含3个不同类型的字段
准备基本帖子
$my_post = array( 'post_title' => 'My post', 'post_content' => 'This is my post.', 'post_status' => 'publish', 'post_author' => 1 );
$post_id = wp_insert_post( $my_post );
// description (text type field) update_field('field_5629f95fc4108', 'description for post', $post_id); // image (Image type field) $image_id = array(1, 2, 3); update_field('field_5621199730caa', $image_id, $post_id); // categories (Taxonomy field type) $categories_ids = array(1, 2, 3); update_field('field_56211b33d0018', $categories_ids, $post_id);