如何在一个中存储多个值meta_key
通过无线电输入,然后在页面上显示这两个值?一个值是文本字符串,另一个值是与该文本相关的链接。这些值不会更改,将由无线框中的数据填充。
这是我的元框的代码。我要收音机event_venue
有一个附加值,可以链接到场馆页面。这样,我只需单击场馆的单选按钮,页面的名称和链接就会自动显示出来。
$meta_box[\'event\'] = array(
\'id\' => \'event-meta-details\',
\'title\' => \'Event Information\',
\'context\' => \'normal\',
\'priority\' => \'high\',
\'fields\' => array(
array(
\'name\' => \'Start Date\',
\'desc\' => \'(Enter yyyy/mm/dd)\',
\'id\' => \'start_date\',
\'type\' => \'text\',
\'default\' => \'\'
),
array(
\'name\' => \'End Date\',
\'desc\' => \'(Enter yyyy/mm/dd)\',
\'id\' => \'end_date\',
\'type\' => \'text\',
\'default\' => \'\'
),
array(
\'name\' => \'Opening\',
\'desc\' => \'YYYY-MM-DD 00:00 24 hour clock\',
\'id\' => \'opening_time\',
\'type\' => \'text\',
\'default\' => \'\'
),
array(
\'name\' => \'Closing\',
\'desc\' => \'YYYY-MM-DD 00:00 24 hour clock\',
\'id\' => \'closing_time\',
\'type\' => \'text\',
\'default\' => \'\'
),
array(
\'name\' => \'Artist Talk - Lecture\',
\'desc\' => \'YYYY-MM-DD 00:00 24 hour clock\',
\'id\' => \'artist_talk_time\',
\'type\' => \'text\',
\'default\' => \'\'
),
array(
\'name\' => \'Venue\',
\'desc\' => \'Venue of Event\',
\'id\' => $prefix . \'event_venue\',
\'type\' => \'radio\',
\'options\' => array(
array(\'name\' => \'William Busta Gallery\', \'value\' => \'William Busta Gallery\'),
array(\'name\' => \'Spaces\', \'value\' => \'Spaces\'),
array(\'name\' => \'Enter Text Below\', \'value\' => \'other\')
)
),
array(
\'name\' => \'Custom Venue\',
\'desc\' => \'Enter Venue Name if Enter Text Below is Checked\',
\'id\' => \'custom_event_venue\',
\'type\' => \'text\',
\'default\' => \'\'
),
array(
\'name\' => \'Featured / Reccomended\',
\'desc\' => \'Recommended Event\',
\'id\' => \'featured_event\',
\'type\' => \'checkbox\',
\'default\' => \'\'
)
)
);
现在我这样显示场地值。
if (get_post_meta(get_the_ID(),\'event_venue\', true) != \'other\') {
echo get_post_meta(get_the_ID(),\'event_venue\', true);
}
if (get_post_meta(get_the_ID(),\'event_venue\', true) == \'other\') {
echo get_post_meta(get_the_ID(),\'custom_event_venue\', true);
}
这是保存数据的代码。
// Save data from meta box
function plib_save_data($post_id) {
global $meta_box, $post;
//Verify nonce
if (!wp_verify_nonce($_POST[\'plib_meta_box_nonce\'], basename(__FILE__))) {
return $post_id;
}
//Check autosave
if (defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE) {
return $post_id;
}
//Check permissions
if (\'page\' == $_POST[\'post_type\']) {
if (!current_user_can(\'edit_page\', $post_id)) {
return $post_id;
}
} elseif (!current_user_can(\'edit_post\', $post_id)) {
return $post_id;
}
foreach ($meta_box[$post->post_type][\'fields\'] as $field) {
$old = get_post_meta($post_id, $field[\'id\'], true);
$new = $_POST[$field[\'id\']];
if ($new && $new != $old) {
update_post_meta($post_id, $field[\'id\'], $new);
} elseif (\'\' == $new && $old) {
delete_post_meta($post_id, $field[\'id\'], $old);
}
}
}
add_action(\'save_post\', \'plib_save_data\');
提前感谢您的建议。我很困惑。