Php wordpress-使用TinyMCE管理post编辑表单中的自定义post meta
我一直在尝试实现一个TinyMCE文本区域,用于添加和编辑帖子元项,下面是我尝试的代码 我能够生成TinyMCE编辑器的后期编辑形式,但无法加载数据库中的后期元数据,有人可以帮助我吗?提前谢谢Php wordpress-使用TinyMCE管理post编辑表单中的自定义post meta,php,wordpress,tinymce,Php,Wordpress,Tinymce,我一直在尝试实现一个TinyMCE文本区域,用于添加和编辑帖子元项,下面是我尝试的代码 我能够生成TinyMCE编辑器的后期编辑形式,但无法加载数据库中的后期元数据,有人可以帮助我吗?提前谢谢 function target_audience_get_meta( $value ) { global $post; $field = get_post_meta( $post->ID, '_target_audience', true ); if ( ! empty( $field ) ) {
function target_audience_get_meta( $value ) {
global $post;
$field = get_post_meta( $post->ID, '_target_audience', true );
if ( ! empty( $field ) ) {
return is_array( $field ) ? stripslashes_deep( $field ) : stripslashes( wp_kses_decode_entities( $field ) );
} else {
return false;
}
}
function target_audience_add_meta_box() {
add_meta_box(
'target_audience',
__( 'Target Audience', 'target_audience' ),
'target_audience_html',
'product',
'normal',
'default'
);
}
function target_audience_html(){
wp_nonce_field( '_target_audience_nonce', 'target_audience_nonce' );
$target_audience = get_post_meta($post->ID, '_target_audience', true);
wp_editor( $target_audience, '_target_audience', array(
'wpautop' => true,
'media_buttons' => false,
'textarea_name' => 'target_audience',
'textarea_rows' => 10,
'teeny' => true
) );
}
function target_audience_save( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if ( ! isset( $_POST['target_audience'] ) || ! wp_verify_nonce( $_POST['target_audience_nonce'], '_target_audience_nonce' ) ) return;
if ( isset( $_POST['target_audience'] ) )
update_post_meta( $post_id, '_target_audience', esc_attr( $_POST['target_audience'] ) );
}
add_action( 'save_post', 'target_audience_save' );
target_audience_get_meta('_target_audience');
问题很简单。我只是忘了将
$post
参数输入函数target\u acquisition\u html($post)
。现在它正在工作。问题很简单。我只是忘了将$post
参数输入函数target\u acquisition\u html($post)
。现在它正在工作