创建一个额外的元框(我想是复选框),它提供了从该帖子创建“编辑”帖子类型的选项。对于这段代码,我们将其称为“transfer\\u data”。
将$post\\U type的值更改为我们将从中检索数据的原始帖子的帖子类型。
我添加了将原始帖子ID保存为“编辑”帖子类型的元值的功能。为了将“编辑”元数据库保存到原始帖子,您应该能够使用该值和该函数(使用update_post_meta()
相反,当然)对另一个要挂接的函数进行反向工程。
function create_edit_page($data){
$post_type = \'the_post_type_to_work_with\';
// Grab this post\'s ID
$orig_id = $_POST[\'post_ID\'];
// Grab the value of the \'transfer_data\' field
$is_transfer_val = get_post_meta( $orig_id, \'transfer_data\');
if($data[\'post_type\'] == $post_type && $is_transfer_val == TRUE &&
isset($data[\'guid\']) && strlen($data[\'guid\'])>0 ){
$post_id = wp_insert_post(
array(
\'comment_status\' => \'closed\',
\'ping_status\' => \'closed\',
\'post_author\' => $data[\'post_author\'],
\'post_name\' => $slug,
\'post_content\' => $data[\'post_content\'],
\'post_title\' => $data[\'post_title\'],
\'post_status\' => \'publish\',
// The custom post type \'editing\'
\'post_type\' => \'editing\'
)
);
// create the meta fields
$all_meta_boxes = get_post_meta( $orig_id );
if(isset( $all_meta_boxes ) && is_array( $all_meta_boxes )){
foreach($all_meta_boxes as $metakey => $metavalue){
add_post_meta($post_id, $metakey, $metavalue);
}
}
// add a meta field that points to original post (for editing purposes, etc.)
add_post_meta($post_id, \'original_post_id\', $orig_id);
// If you want to redirect the user after saving use the filter below
// add_filter(\'redirect_post_location\', \'my_post_redirect_filter\', \'99\');
return $data;
}
return $data;
}
add_action( \'wp_insert_post\', \'create_edit_page\', \'99\' );
// Or, call BEFORE updating the database with below action
//add_action( \'wp_insert_post_data\', \'create_edit_page\', \'99\' );