这已在中解决another post, 但解决方案过于具体,无法在这里应用。
我的目标是使用metabox值(ecpt\\u name)作为帖子标题,这样用户只需输入一次自己的名字,这个名字就会出现在管理员帖子列表和在线中。
现在,我要求用户将文章标题作为全名输入到元框中。这使我可以在线显示全名,并在管理帖子列表中显示全名,但这是工作量的两倍。
正在寻找一些可以应用到函数中的内容。钩住ecpt\\u name元框值并将其放置到post\\u title名称中的php。thx-史蒂夫
这已在中解决another post, 但解决方案过于具体,无法在这里应用。
我的目标是使用metabox值(ecpt\\u name)作为帖子标题,这样用户只需输入一次自己的名字,这个名字就会出现在管理员帖子列表和在线中。
现在,我要求用户将文章标题作为全名输入到元框中。这使我可以在线显示全名,并在管理帖子列表中显示全名,但这是工作量的两倍。
正在寻找一些可以应用到函数中的内容。钩住ecpt\\u name元框值并将其放置到post\\u title名称中的php。thx-史蒂夫
<?php
add_action( \'save_post\', \'post_updated\' );
function post_updated( $post_id ) {
// verify post is not a revision & not an autosave
if ( !wp_is_post_revision( $post_id ) && !(defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE) ) {
// set the new post title
$post[\'ID\'] = $post_id;
$post[\'post_title\'] = get_post_meta($post_id, \'ecpt_name\', true);
// update the post, removing the action to prevent an infinite loop
remove_action( \'save_post\', \'post_updated\' );
wp_update_post($post);
add_action( \'save_post\', \'post_updated\' );
}
}
?>
谢谢你的回复。必须澄清的是,我需要这样做只是为了影响某个CPT,而不是所有的职位。根据以下修改。然而,旧的帖子标题仍然显示在管理帖子列表中。必须找到解决方案。
// draw post title from name metabox on CPT student
add_action( \'save_post\', \'post_updated\' );
function post_updated( $post_id ) {
// affect only CPT student
if ($post_type == \'student\') {
// set the new post title
$post[\'ID\'] = $post_id;
$post[\'post_title\'] = get_post_meta($post_id, \'ecpt_name\', true);
// update the post, removing the action to prevent an infinite loop
remove_action( \'save_post\', \'post_updated\' );
wp_update_post($post);
add_action( \'save_post\', \'post_updated\' );
}
}
我正试图将WP Pluploader放入我帖子页面的元框中-根据Plupload Intergration in a meta-box? 和http://www.krishnakantsharma.com/2012/01/image-uploads-on-wordpress-admin-screens-using-jquery-and-new-plupload/我在第二个链接中的示例中实现了这一切。然而,我想把它全部放在一个类文件中。如果我把它全部打包成一个类,它就会停止工作。这都是因为:function