我不知道WordPress是否能夠在Quick Edits
的標籤添加2個字段(輸入和textarea)。我怎樣才能擴展快速編輯選項與2個字段
其實這2個領域我想在Quick Edit
這是在編輯標籤頁可以添加,但我想,以顯示Quick Edit
這2場,所以我就能夠很容易地訪問它們。
碼:
// Add a dummy column for the `posts` post type
add_filter('manage_edit-post_tag_columns', 'add_dummy_column', 10, 2);
function add_dummy_column($columns)
{
$columns['headline'] = 'Headline';
$columns['intro-text'] = 'Intro Text';
return $columns;
}
// But remove it again on the edit screen (other screens to?)
add_filter('manage_edit-post_tag_columns', 'remove_dummy_column');
function remove_dummy_column($columns)
{
unset($columns['description']);
return $columns;
}
function my_column_value($empty = '', $custom_column, $term_id)
{
include_once('taxonomy-metadata.php');
return esc_html(get_term_meta($term_id, $custom_column, true));
}
add_filter('manage_post_tag_custom_column', 'my_column_value', 10, 3);
function my_quick_edit_custom_box($column_name, $screen, $name)
{
if($name != 'post_tag' && ($column_name != 'headline' || $column_name != 'intro-text')) return false;
if($name == 'post_tag' && $column_name == 'headline') {
?>
<fieldset>
<div id="my-custom-content" class="inline-edit-col">
<label>
<span class="title"><?php if($column_name == 'headline') _e('Headline', 'ie_tag_plugin'); else _e('Intro text', 'ie_tag_plugin'); ?></span>
<span class="input-text-wrap"><input name="<?php echo $column_name; ?>" class="ptitle" value="" type="text"></span>
</label>
</div>
</fieldset>
<?php
}
if($name == 'post_tag' && $column_name == 'intro-text') {
?>
<fieldset>
<div id="my-custom-content" class="inline-edit-col">
<label>
<span class="title"><?php if($column_name == 'headline') _e('Headline', 'ie_tag_plugin'); else _e('Intro text', 'ie_tag_plugin'); ?></span>
<span class="input-text-wrap"><textarea name="<?php echo $column_name; ?>" class="ptitle"><?php $data = esc_html($data); ?></textarea></span>
</label>
</div>
</fieldset>
<?php
}
}
add_action('quick_edit_custom_box', 'my_quick_edit_custom_box', 10, 3);
function my_save_term_meta($term_id)
{
$allowed_html = array(
'b' => array(),
'em' => array(),
'i' => array(),
'strike' => array(),
'strong' => array(),
);
if(isset($_POST['headline']))
update_term_meta($term_id, 'headline', wp_kses($_POST['headline'], $allowed_html));
if(isset($_POST['intro-text']))
update_term_meta($term_id, 'intro-text', wp_kses($_POST['intro-text'], $allowed_html));
}
add_action('edited_post_tag', 'my_save_term_meta', 10, 1);
我試圖這樣做,但這些代碼不會保存數據,似乎都在做這後一個爛攤子。
有沒有辦法做這個任務,那麼請讓我知道。我將非常感激。
謝謝大家。
'edited_president'不是一個被認可的Wordpress動作鉤子。嘗試將最後一行改爲:'add_action('edited_term','my_save_term_meta',10,1);'讓我知道發生了什麼(如果它有效,產生錯誤或什麼都不做)。 – maiorano84
如果失敗,請嘗試'edit_post_tag'而不是'edited_term'。 – maiorano84
我已經嘗試了兩種方式,但不能正常工作。 – Muzzy