我目前有许多自定义元数据库,每个看起来都非常类似:
/* -----------------------------------------------------------
# Team Information
----------------------------------------------------------- */
add_action( \'add_meta_boxes\', \'team_information_metabox\' );
function team_information_metabox()
{
add_meta_box(\'team_information\', \'Team Information\', \'team_information_output\', \'page\', \'normal\', \'high\');
}
function team_information_output( $post )
{
//so, dont ned to use esc_attr in front of get_post_meta
$team_information_value= get_post_meta($_GET[\'post\'], \'team_information\' , true ) ;
wp_editor( $team_information_value, \'team-information\', $settings = array(\'textarea_name\'=>\'team-information\') );
}
function save_team_information( $post_id )
{
if (!empty($_POST[\'team-information\']))
{
$data=$_POST[\'team-information\'];
update_post_meta($post_id, \'team_information\', $data );
}
}
add_action( \'save_post\', \'save_team_information\' );
我将它们显示在如下页面上:
$team_information_value = get_post_meta( get_the_ID(), \'team_information\', true );
// Checks and displays the retrieved value
if( !empty( $team_information_value ) ) {
echo $team_information_value;
} else {
echo \'Value Not Fount or Empty\';
}
出于某种原因,当我这样做时,短代码不起作用,如何从中获得短代码功能?
最合适的回答,由SO网友:Trenton Moore 整理而成
找到了答案:
$team\\u information\\u value=get\\u post\\u meta(get\\u the\\u ID(),\'team\\u information\',true);
// Checks and displays the retrieved value
if( !empty( $team_information_value ) ) {
echo do_shortcode($team_information_value);
} else {
echo \'Value Not Fount or Empty\';
}
将显示的值(在本例中为$team\\u information\\u value)放入do\\u shortcode()中;