admin管理员组文章数量:1391987
How can I add custom field (textarea) to wordpress taxonomy (tag)?
add_action('admin_init', 'tag_custom_fields', 1);
if( !function_exists('tag_custom_fields') ) {
function tag_custom_fields()
{
add_action('edit_category_form_fields', 'tag_custom_fields_form');
add_action('edited_category', 'tag_custom_fields_save');
add_action( 'create_category', 'tag_custom_fields_save');
add_action( 'category_add_form_fields', 'tag_custom_fields_form_new');
}
}
if( !function_exists('tag_custom_fields_form') ) {
function tag_custom_fields_form($term)
{
$t_id = $term->term_id;
$term_meta = get_option( "taxonomy_$t_id" );
wp_enqueue_script('wp-color-picker');
wp_enqueue_style( 'wp-color-picker' );
?>
<?php $settingseditor = array(
'textarea_name' => 'description',
'textarea_rows' => 10,
'editor_class' => 'i18n-multilingual',
);
?>
<tr class="form-field">
<th scope="row" valign="top"><label><?php esc_html_e('Second tag description','framework'); ?></label></th>
<td>
<?php
$meta_content = !empty($term_meta['tag_second_description']) ? $term_meta['tag_second_description'] : '';
wp_editor( $meta_content, 'tag_second_description', array(
'wpautop' => true,
'media_buttons' => false,
'textarea_name' => 'term_meta[tag_second_description]',
'textarea_rows' => 10,
'teeny' => false
));
?>
<span class="description"><?php esc_html_e('Set html for second category description (will be after posts)','framework'); ?></span>
</td>
</tr>
<?php
}
}
if( !function_exists('tag_custom_fields_form_new') ) {
function tag_custom_fields_form_new($term)
{
wp_enqueue_script('wp-color-picker');
wp_enqueue_style( 'wp-color-picker' );
?>
<div class="form-field">
<label><?php esc_html_e('Second tag description','framework'); ?></label>
<textarea name="term_meta[tag_second_description]" id=team_meta[tag_second_description]" rows="5" cols="50"><?php echo (!empty($term_meta['tag_second_description'])) ? $term_meta['tag_second_description'] : ''; ?></textarea><br />
<span class="description"><?php esc_html_e('Set html for second category description (will be after posts)','framework'); ?></span>
</div>
<?php
}
}
if( !function_exists('tag_custom_fields_save') ) {
function tag_custom_fields_save($term_id)
{
if (isset($_POST['term_meta'])) {
$t_id = $term_id;
$term_meta = get_option("taxonomy_$t_id");
$cat_keys = array_keys($_POST['term_meta']);
foreach ($cat_keys as $key) {
if (isset($_POST['term_meta'][$key])) {
$term_meta[$key] = stripslashes($_POST['term_meta'][$key]);
}
}
//save the option array
update_option("taxonomy_$t_id", $term_meta);
}
}
}
I have this code above but it adds a field to the category. I don't know how to make it add a field to the tag.
本文标签: customizationHow to add textarea field to taxonomy (tag)
版权声明:本文标题:customization - How to add textarea field to taxonomy (tag)? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744746116a2622888.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论