我根据这个播放列表在自定义帖子中开发了 Meta Box 插件。(我对此做了一些自定义)在这里,他使用插件创建了一个自定义帖子,并对该相关帖子执行所有元框操作。
它工作正常。但我的要求是在页面中显示这个元框。
这是我的代码。
metabox.php(插件代码)
<?php
function wpl_owt_custom_init_cpt(){
$args = array(
'public' => true,
'label' => 'Books',
'supports' => array('title' , 'editor' , 'author' , 'thumbnail' , 'excerpt' , 'comments')
);
register_post_type('book' , $args);
}
add_action('init', 'wpl_owt_custom_init_cpt');
function wpl_owt_register_metabox_cpt(){
//custom post type
add_meta_box("owt-cpt-id" , "Contact Details" , "wpl_owt_book_function" , "book" , "normal" , "high");
}
add_action("add_meta_boxes_book" , "wpl_owt_register_metabox_cpt");
/**********Callback function for metabox at custom post type book******************/
function wpl_owt_book_function( $post ) {
//echo "<p>Custom metabox for custom post type</p>";
define("_FILE_", "_FILE_");
wp_nonce_field( basename(_FILE_), "wp_owt_cpt_nonce");
echo "<label for='txtPhoneNum'>Phone</label><br>";
$phone_num = get_post_meta($post->ID, "telNo" , true);
echo "<input type ='tel' name = 'txtPhoneNum' value = '" . $phone_num . "'' placeholder = 'Phone Number' /><br><br>";
echo "<label for='txtEmail'>Email</label><br>";
$email = get_post_meta($post->ID, "email" , true);
echo "<input type ='email' name = 'txtEmail' value = '" . $email . "'' placeholder = 'Email Address' /><br><br>";
echo "<label for='txtHours'>Hours of Operation</label><br>";
$hours = get_post_meta($post->ID, "hourofOps" , true);
echo "<input type ='text' name = 'txtHours' value = '" . $hours . "'' placeholder = 'Working Hours' /><br><br>";
}
add_action("save_post" , "wpl_owt_save_metabox_data" , 10 , 2);
function wpl_owt_save_metabox_data($post_id, $post){
//verify nonce
if(!isset($_POST['wp_owt_cpt_nonce']) || !wp_verify_nonce($_POST['wp_owt_cpt_nonce'], basename(_FILE_))){
return $post_id;
}
幕布斯6054654
SMILET