admin管理员组文章数量:1130349
i found nothing about it in the WP reference and Google, so i ask you: I want to update a post by a form - and with it its children.
$post = array(
'ID' => $mainid,
'post_status' => 'wartend'
);
$lead = wp_update_post($post);
$children = get_children( $mainid );
foreach ($children as $child){
wp_update_post(
array(
'ID' => $child,
'post_status' => 'wartend',
'post_parent' => $mainid
)
);
}
The post is getting updated, but not the children.
i found nothing about it in the WP reference and Google, so i ask you: I want to update a post by a form - and with it its children.
$post = array(
'ID' => $mainid,
'post_status' => 'wartend'
);
$lead = wp_update_post($post);
$children = get_children( $mainid );
foreach ($children as $child){
wp_update_post(
array(
'ID' => $child,
'post_status' => 'wartend',
'post_parent' => $mainid
)
);
}
The post is getting updated, but not the children.
Share Improve this question asked Nov 19, 2018 at 4:16 PlatoPlato 31 bronze badge 2- What is the type of these posts? – Krzysiek Dróżdż Commented Nov 19, 2018 at 6:22
- Its a custom post type ^^ i didnt liked woocommerce, so i wrote a own shopping solution with custom fields and custom post type. Was more affort than i thought, but works really well. – Plato Commented Nov 19, 2018 at 15:07
1 Answer
Reset to default 0get_children returns an array of post objects by default:
https://developer.wordpress/reference/functions/get_children/
So you would have to use 'ID' => $child->ID, in this case... also my want to wrap the foreach with if (count($children) > 0) {} to prevent possible errors where there are no children. ie:
$children = get_children( $mainid );
if (count($children) > 0) {
foreach ($children as $child){
wp_update_post(
array(
'ID' => $child->ID,
'post_status' => 'wartend',
'post_parent' => $mainid
)
);
}
}
}
i found nothing about it in the WP reference and Google, so i ask you: I want to update a post by a form - and with it its children.
$post = array(
'ID' => $mainid,
'post_status' => 'wartend'
);
$lead = wp_update_post($post);
$children = get_children( $mainid );
foreach ($children as $child){
wp_update_post(
array(
'ID' => $child,
'post_status' => 'wartend',
'post_parent' => $mainid
)
);
}
The post is getting updated, but not the children.
i found nothing about it in the WP reference and Google, so i ask you: I want to update a post by a form - and with it its children.
$post = array(
'ID' => $mainid,
'post_status' => 'wartend'
);
$lead = wp_update_post($post);
$children = get_children( $mainid );
foreach ($children as $child){
wp_update_post(
array(
'ID' => $child,
'post_status' => 'wartend',
'post_parent' => $mainid
)
);
}
The post is getting updated, but not the children.
Share Improve this question asked Nov 19, 2018 at 4:16 PlatoPlato 31 bronze badge 2- What is the type of these posts? – Krzysiek Dróżdż Commented Nov 19, 2018 at 6:22
- Its a custom post type ^^ i didnt liked woocommerce, so i wrote a own shopping solution with custom fields and custom post type. Was more affort than i thought, but works really well. – Plato Commented Nov 19, 2018 at 15:07
1 Answer
Reset to default 0get_children returns an array of post objects by default:
https://developer.wordpress/reference/functions/get_children/
So you would have to use 'ID' => $child->ID, in this case... also my want to wrap the foreach with if (count($children) > 0) {} to prevent possible errors where there are no children. ie:
$children = get_children( $mainid );
if (count($children) > 0) {
foreach ($children as $child){
wp_update_post(
array(
'ID' => $child->ID,
'post_status' => 'wartend',
'post_parent' => $mainid
)
);
}
}
}
本文标签: front endHow to update the children of a post
版权声明:本文标题:front end - How to update the children of a post? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749170056a2326847.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论