在页面上显示自定义元框

时间:2014-01-08 15:40:48

标签: wordpress

我想在页面模板中显示元数据的值。 谢谢先进!!

这是metabox的代码

function traduccion_add_custom_box() {
    $screens = array( 'page' );
    foreach ( $screens as $screen ) {
        add_meta_box(
            'traduccion_sectionid',
            __( 'Inglés', 'traduccion_textdomain' ),
            'traduccion_inner_custom_box',
            $screen
        );
    }
}
add_action( 'add_meta_boxes', 'traduccion_add_custom_box' );

function traduccion_inner_custom_box( $post ) {
  wp_nonce_field( 'traduccion_inner_custom_box', 'traduccion_inner_custom_box_nonce' );
  $ingles = get_post_meta( $post->ID, '_my_meta_value_key', true );
  wp_editor( $ingles, 'traduccion_new_field' );
}

我在我的页面模板中尝试此操作但不起作用

<?php
        $custom = get_post_meta($post->ID);
        $display_ingles = $custom['ingles'][0];
    ?>          

    <?php echo $display_ingles; ?>

1 个答案:

答案 0 :(得分:1)

get_post_meta函数缺少meta_key变量,如果将单个变量设置为true,则不需要[0]。代码应如下所示:

<?php
    $custom = get_post_meta($post->ID, '_my_meta_value_key', true);
    $display_ingles = $custom;

    echo $display_ingles;
?>