您可以通过使用后期编辑钩子过滤器/操作来实现这一点。这样地
add_action( 'edit_post', 'parentsetter_save_post' );
function parentsetter_save_post()
{
global $post;
$custom_field=get_post_meta($post->ID,'customfieldname',true);
if ($custom_field!=''){
$parent_page=get_page_by_title($custom_field);
if (!empty($parent_page) and $post->post_parent!=$parent_page->ID){
global $wpdb;
$wpdb->query($wpdb->prepare("update $wpdb->posts set post_parent=%d
where ID=%d",$parent_page->ID,$post->ID));
}
}
}
只要用您的自定义字段名替换“custom field name”,它就可以工作了。