【发布时间】:2017-05-23 23:29:41
【问题描述】:
我有一个用于推荐的自定义帖子类型,其工作方式与我期望的一样。下面是推荐的sn-p代码
add_action( 'init', 'register_cpt_testimonial' );
function register_cpt_testimonial() {
...
$args = array(
..
);
register_post_type( 'testimonial', $args );
}
但是,现在我想花哨并添加元框,但我无法显示它。
function testimonial_meta_boxes() {
add_meta_box( 'testimonial_form', 'Testimonial Details', 'testimonial_form', 'testimonial', 'side', 'high' );
}
function testimonial_form() {
$post_id = get_the_ID();
$testimonial_data = get_post_meta( $post_id, '_testimonial', true );
$client_name = ( empty( $testimonial_data['client_name'] ) ) ? '' : $testimonial_data['client_name'];
wp_nonce_field( 'testimonial', 'testimonial' );
?>
<p>
<label>Client's Name (optional)</label><br />
<input type="text" value="<?php echo $client_name; ?>" name="testimonial[client_name]" size="40" />
</p>
<?php
}
有人可以解释一下我在这里缺少什么。我正在阅读https://developer.wordpress.org/reference/functions/add_meta_box/,但我只是不明白我所缺少的。
【问题讨论】:
-
元框未显示在管理面板中?
标签: wordpress wordpress-theming