您可以使用save_post
像这样钩住:
function set_post_parent_on_save($post_id) {
// If this is just a revision, don\'t do anything
if ( wp_is_post_revision( $post_id ) )
return;
// Check if it is a post
if ( \'post\' == get_post_type( $post_id ) ) {
// unhook this function so it doesn\'t loop infinitely
remove_action( \'save_post\', \'set_post_parent_on_save\' );
// update the post, which calls save_post again
wp_update_post( array(
\'ID\' => $post_id,
\'post_parent\' => 88 // <- or whatever the parent should be
) );
// re-hook this function
add_action( \'save_post\', \'set_post_parent_on_save\' );
}
}
add_action( \'save_post\', \'set_post_parent_on_save\' );
但是。。。这样做不是最好的主意,我更愿意看看面包屑的生成方式,并尝试修复它,这样它才能正常工作。