你好,美丽的WP社区。我设法拼凑出一个解决方案,以防有人需要。我肯定它需要清理一下,但它确实管用。令人敬畏的是,它是多用途的——只要将$args更改为硬编码,即可在更新父帖子时对子帖子中的标记、键、类别、标题、作者、状态、模板或内容进行任何更改。
What it doesn\'t do: 不幸的是,一位无法帮助的狂热用户错误地否决了这个问题,认为它是重复的(事实并非如此)。这completely different function 保存父帖子时,不会自动更新子分类法以匹配父分类法(仍在寻找答案),但同时,您可以将以下函数与this completely different question here 为了实现这一目标。
继续让这个地方变得棒极了!
add_action( \'save_post\', \'update_children\', 10, 2);
function update_children( $post_id, $post ) {
if ( \'trash\' != $post->post_status ){
// Is a top level post
if( 0 === $post->post_parent ) {
$children = array(
\'post_parent\' => $post->ID,
\'post_type\' => \'any\', //you can use also \'any\'
\'fields\' => \'ids\', // Only Return IDs
\'post_status\' => \'publish\',
);
global $post;
if ((is_array($children))&&(!empty( $children ))){
$the_query = new WP_Query( $children );
}
// The Loop
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
$mypostids[] = get_the_ID();
$updatethis = array (
\'fields\' => $mypostids,
\'post_status\' => \'publish\'
);
if ((is_array($children))&&(!empty( $children ))) {
foreach( $children as $child_ids ) {
remove_action( \'save_post\', \'update_children\', 10, 2);
wp_update_post( $updatethis );
add_action( \'save_post\', \'update_children\', 10, 2);
}
}
endwhile;
endif;
}
}
}