高级自定义字段 - 以编程方式插入 post 并更新转发器字段
advanced custom fields - insert post programmatically and update repeater fields
我的插件有问题 "Advanced Custom Fields"。我遵循的步骤是:
1.以编程方式创建 post
$id_post = wp_insert_post(array(
'post_type'=>$post_type,
'post_title'=>$post_title,
'post_status' => 'publish'
));
2。更新与 "post_type"
关联的所有转发器字段
if( have_rows('cliente',$id_post) ) {
$i = 0;
while( have_rows('cliente',$id_post) ) {
the_row();
update_sub_field('id', 333);
}
}
问题出在第 2 点,事实上,当我使用 Wordpress 界面(带有按钮)创建 post 并在我的代码中手动插入 post 的 ID 时,它完美运行..
但是当我在第二点以编程方式创建 post 时,即使我以编程方式输入 post 创建的编号,转发器字段也无法识别。
仅当 post 是使用按钮 "Insert New" 创建时才有效。
你有什么建议吗?
感谢大家!
请参阅说明如何以编程方式创建和更新字段的教程。
http://www.pearlbells.co.uk/insert-udpate-wordpress-post-programmatically/
$newIds = wp_insert_post( array(
'post_title' => $postCSVContent['1'],
'post_content' => $postCSVContent['2'],
'post_type' => 'doors',
'post_status' => 'publish',
'post_author' => 1,
'post_parent' => $parentId
));
updateAcf( $postCSVContent , $newIds );
更新 acf 图像转发器字段:
http://www.pearlbells.co.uk/insert-update-acf-image-repeater-field-programmatically/
我已经解决了问题!问题与字段名称有关。您必须使用键而不是名称。我现在的代码是
$cliente_data = array( array( "id" => 33 ) );
update_field('field_582c2ed4fab65', $cliente_data, $id_post );
我的插件有问题 "Advanced Custom Fields"。我遵循的步骤是:
1.以编程方式创建 post
$id_post = wp_insert_post(array(
'post_type'=>$post_type,
'post_title'=>$post_title,
'post_status' => 'publish'
));
2。更新与 "post_type"
关联的所有转发器字段if( have_rows('cliente',$id_post) ) {
$i = 0;
while( have_rows('cliente',$id_post) ) {
the_row();
update_sub_field('id', 333);
}
}
问题出在第 2 点,事实上,当我使用 Wordpress 界面(带有按钮)创建 post 并在我的代码中手动插入 post 的 ID 时,它完美运行..
但是当我在第二点以编程方式创建 post 时,即使我以编程方式输入 post 创建的编号,转发器字段也无法识别。
仅当 post 是使用按钮 "Insert New" 创建时才有效。
你有什么建议吗?
感谢大家!
请参阅说明如何以编程方式创建和更新字段的教程。 http://www.pearlbells.co.uk/insert-udpate-wordpress-post-programmatically/
$newIds = wp_insert_post( array(
'post_title' => $postCSVContent['1'],
'post_content' => $postCSVContent['2'],
'post_type' => 'doors',
'post_status' => 'publish',
'post_author' => 1,
'post_parent' => $parentId
));
updateAcf( $postCSVContent , $newIds );
更新 acf 图像转发器字段: http://www.pearlbells.co.uk/insert-update-acf-image-repeater-field-programmatically/
我已经解决了问题!问题与字段名称有关。您必须使用键而不是名称。我现在的代码是
$cliente_data = array( array( "id" => 33 ) );
update_field('field_582c2ed4fab65', $cliente_data, $id_post );