我正在开发一个小插件,其中一部分需要向所有自定义帖子类型添加几个元框。我尝试过以各种方式循环使用自定义端口类型的数组,但我不断遇到错误,我已经调用了add\\u meta\\u box等函数。下面的脚本是我的最新成果,它没有保存最后三个元框(仅第一个)中的值。
我真的想缩小这个尺寸。我正在使用一个类,根据我在网络图茨插件课程上学到的一些东西。它在其他方面还可以,但PHP不是我的强项,所以我被卡住了!是否有人可以帮助我循环或将自定义帖子类型的数组传递给函数add\\u meta\\u box?
这是相关脚本的一部分,对不起,这是一个很大的。。
//meta boxes...
public function meta_boxes(){
//load the array into a var
$all_post_types = $this->post_types;
$just_trades = array();
foreach($all_post_types as $trade){
$just_trades[] = $trade[\'post_type_name\'];
}
//call the action
add_action(\'add_meta_boxes\',\'make_meta_box\');
function make_meta_box(){
//make array of all meta boxes we want to show..
add_meta_box(\'landline\',\'Landline Phone Number\',\'landline_function\',$just_trades);//id, UI, the function, what page it shows on
add_meta_box(\'mobile\',\'Mobile Phone Number\',\'mobile_function\',$just_trades);//id, UI, the function, what page it shows on
add_meta_box(\'email\',\'Email Address\',\'email_function\',$just_trades);//id, UI, the function, what page it shows on
add_meta_box(\'website\',\'Website URL\',\'website_function\',$just_trades);//id, UI, the function, what page it shows on
}
function landline_function($post){ // function that makes the HTML for the admin UI
$landline = get_post_meta($post->ID,\'landline\',true);// id is available, the key we want, return a single or array value. Single for this.
?>
<label for="landline">Landline Number: </label>
<input type="text" class="widefat" name="landline" id="landline" value="<?php echo $landline;?>" />
<?php
}
add_action(\'save_post\',\'save_landline\');
function save_landline($id){ // ID is available by default
if(isset($_POST[\'landline\'])){
update_post_meta($id,\'landline\',strip_tags($_POST[\'landline\']));
}
}
function mobile_function($post){ // function that makes the HTML for the admin UI
$mobile = get_post_meta($post->ID,\'mobile\',true);// id is available, the key we want, return a single or array value. Single for this.
?>
<label for="mobile">Mobile Number: </label>
<input type="text" class="widefat" name="mobile" id="mobile" value="<?php echo $mobile;?>" />
<?php
}
add_action(\'save_post\',\'save_mobile\');
function save_mobile($id){ // ID is available by default
if(isset($_POST[\'mobile\'])){
update_post_meta($id,\'mobile\',strip_tags($_POST[\'mobile\']));
}
}
function email_function($post){ // function that makes the HTML for the admin UI
$email = get_post_meta($post->ID,\'email\',true);// id is available, the key we want, return a single or array value. Single for this.
?>
<label for="email">Email: </label>
<input type="text" class="widefat" name="email" id="email" value="<?php echo $email;?>" />
<?php
}
add_action(\'save_post\',\'save_email\');
function save_email($id){ // ID is available by default
if(isset($_POST[\'email\'])){
update_post_meta($id,\'email\',strip_tags($_POST[\'email\']));
}
}
function website_function($post){ // function that makes the HTML for the admin UI
$website = get_post_meta($post->ID,\'website\',true);// id is available, the key we want, return a single or array value. Single for this.
?>
<label for="website">Website: </label>
<input type="text" class="widefat" name="website" id="website" value="<?php echo $website;?>" />
<?php
}
add_action(\'save_post\',\'save_website\');
function save_website($id){ // ID is available by default
if(isset($_POST[\'website\'])){
update_post_meta($id,\'website\',strip_tags($_POST[\'website\']));
}
}
}
。。任何帮助都会很好。丹。