我有一个自定义的职位类型“career\\u opportunities”,带有“responsibilities”文本框:
<p><label for="responsibilities">Responsibilities</label></p>
<?php wp_editor(
"",
"responsibilities",
array(
\'textarea_name\' => \'responsibilities\',
\'tinymce\'=>true
)); ?>
问题是,当我调用“save\\u post”时,它没有保存:
add_action( \'save_post\', \'save_career_opportunity\' );
/* When the post is saved, saves our custom data */
function save_career_opportunity( $post_id ) {
if ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE )
return;
if( !isset( $_POST[\'career_nonce\'] ) || !wp_verify_nonce( $_POST[\'career_nonce\'], \'my_meta_box_career_nonce\' ) )
return;
if ( \'page\' == $_POST[\'post_type\'] )
{
if ( !current_user_can( \'edit_page\', $post_id ) )
return;
} else {
if ( !current_user_can( \'edit_post\', $post_id ) )
return;
}
$responsibilities = $_POST[\'responsibilities\']; // longer description
$qualifications = $_POST[\'qualifications\']; // longer description
$career_level = $_POST[\'career_level\']; //
$minimum_education = $_POST[\'minimum_education\'];
$job_status = $_POST[\'job_status\'];
update_post_meta($post_id, \'responsibilities\', $_POST[\'responsibilities\']);
update_post_meta($post_id, \'qualifications\', $_POST[\'qualifications\']);
update_post_meta($post_id, \'career_level\', $_POST[\'career_level\']);
update_post_meta($post_id, \'minimum_education\', $_POST[\'minimum_education\']);
update_post_meta($post_id, \'job_status\', $_POST[\'job_status\']);
}
最合适的回答,由SO网友:Jared 整理而成
关于你的问题上发布的评论@ungestaltbar,这就是他们的意思。您正在存储$_POST
将数据转换为变量,但不使用它们,使它们变得无用。这并不能解决你的问题,但我想澄清一下
或者,您可以确切地看到传递到下一页的内容。我稍微整理了一下代码,尝试一下,看看责任数据是否传递给它。这将是我调试您的问题所做的第一件事。
add_action( \'save_post\', \'save_career_opportunity\' );
/* When the post is saved, saves our custom data */
function save_career_opportunity( $post_id ) {
if ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE )
return;
if( !isset( $_POST[\'career_nonce\'] ) || !wp_verify_nonce( $_POST[\'career_nonce\'], \'my_meta_box_career_nonce\' ) )
return;
if ( \'page\' == $_POST[\'post_type\'] ) {
if ( !current_user_can( \'edit_page\', $post_id ) )
return;
} else {
if ( !current_user_can( \'edit_post\', $post_id ) )
return;
}
die( var_dump( $_POST ) ); // See exactly what is being passed to this function
extract( $_POST );
update_post_meta( $post_id, \'responsibilities\', $responsibilities );
update_post_meta( $post_id, \'qualifications\', $qualifications );
update_post_meta( $post_id, \'career_level\', $career_level );
update_post_meta( $post_id, \'minimum_education\', $minimum_education );
update_post_meta( $post_id, \'job_status\', $job_status );
}
如果不是,那么我们可以放心地假设它与您用来保存帖子的函数无关,但问题在于(可能)
wp_editor
或者你的元框本身。尝试一下,看看会发生什么,如果在将代码更改为上述代码后无法看到职责数据,那么我们可能需要查看更多的元框代码。