function wporg_add_custom_box(){
$screens = ['product', 'wporg_cpt'];
foreach ($screens as $screen) {
add_meta_box(
'wporg_box_id', // Unique ID
'Select a Authors Name ', // Box title
'wporg_custom_box_html', // Content callback, must be of type callable
$screen// Post type
);
}
}
add_action('edit_form_after_title', 'wporg_add_custom_box');
function wporg_custom_box_html($post){
$value = http://www.srcmini.com/get_post_meta($post->
ID,'_getwriter_id', true);
?>
<
select name="book_writer_id" id="book_writer_id" class="postbox">
<
?php
$type = 'book_authors';
// your post type
$args=array(
'post_type' =>
$type, 'post_status' =>
'publish', 'posts_per_page' =>
-1, 'caller_get_posts'=>
1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->
have_posts() ) {
while ($my_query->
have_posts()) : $my_query->
the_post();
$id = get_the_ID();
?>
<
option value="http://www.srcmini.com/<
?=$id;
?>" <
?php selected($value, $id);
?>
>
<
?=the_title();
?>
<
/option>
<
?php
endwhile;
}
wp_reset_query();
// Restore global post data stomped by the_post().
?>
<
/select>
<
?php }
function wporg_save_postdata($post_id)
{
if (array_key_exists('book_writer_id', $_POST)) {
update_post_meta(
$post_id, '_getwriter_id', $_POST['book_writer_id']
);
}
}
add_action('save_post', 'wporg_save_postdata');
#1【WordPress的meta-box不保存和更新】我没有在那里使用save_postdate函数, 为什么, 它不保存值和更新数据
function wporg_add_custom_box(){
$screens = ['product', 'wporg_cpt'];
foreach ($screens as $screen) {
add_meta_box(
'wporg_box_id', // Unique ID
'Select a Authors Name ', // Box title
'wporg_custom_box_html', // Content callback, must be of type callable
$screen// Post type
);
}
}
add_action('edit_form_after_title', 'wporg_add_custom_box');
function wporg_custom_box_html($post)
{
$value = http://www.srcmini.com/get_post_meta($post->
ID,'_getwriter_id', true);
?>
<
select name="book_writer_id" id="book_writer_id" class="postbox">
<
?php
$type = 'book_authors';
// your post type
$args=array(
'post_type' =>
$type, 'post_status' =>
'publish', 'posts_per_page' =>
-1, 'caller_get_posts'=>
1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->
have_posts() ) {
while ($my_query->
have_posts()) : $my_query->
the_post();
$id = get_the_ID();
?>
<
option value="http://www.srcmini.com/<
?=$id;
?>" <
?php selected($value, $id);
?>
>
<
?=the_title();
?>
<
/option>
<
?php
endwhile;
}
wp_reset_query();
// Restore global post data stomped by the_post().
?>
<
/select>
<
?php
}function wporg_save_postdata($post_id)
{
if (array_key_exists('book_writer_id', $_POST)) {
update_post_meta(
$post_id, '_getwriter_id', $_POST['book_writer_id']
);
}
}
add_action('save_post', 'wporg_save_postdata');
推荐阅读
- WordPress(主页上的多列)
- WordPress菜单链接不适用于左键单击
- WordPress菜单-将类别添加到锚点
- WordPress菜单未在网站上显示,但在控制台日志和移动设备中可见
- WordPress菜单在标签中添加类
- WordPress的主要类别与ghost类别
- 具有不同bootstrap列的WordPress循环
- WordPress –为不同页面加载不同的CSS无法正常工作
- WordPress(将function.php放入队列后无法加载javascript)