post_tags_meta_box

Display post tags form fields.

Description

post_tags_meta_box( (WP_Post) $post, (array) $box ); 

Parameters (2)

0. $post (WP_Post)
Post object.
1. $box (array)
Tags meta box arguments.

Options

  • id (string) => ''

    Meta box id attribute.

  • title (string) => ''

    Meta box title.

  • args (array) => array()

    Extra meta box arguments.

    • taxonomy (string) => 'post_tag'

      Taxonomy.

array(

    /**
     * Meta box 'id' attribute.
     *
     * @type string
     * @default ''
     */
    'id' => '',

    /**
     * Meta box title.
     *
     * @type string
     * @default ''
     */
    'title' => '',

    /**
     * Extra meta box arguments.
     *
     * @type array
     */
    'args' => array(

        /**
         * Taxonomy.
         *
         * @type string
         * @default 'post_tag'
         */
        'taxonomy' => 'post_tag'
    )
);        


Usage

  1. if ( !function_exists( 'post_tags_meta_box' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/meta-boxes.php'; 
  3.  
  4. // Post object. 
  5. $post = null; 
  6.  
  7. // Tags meta box arguments. 
  8. $box = array( 
  9. 'id' => '', 
  10. 'title' => '', 
  11. 'args' => array( 
  12. 'taxonomy' => 'post_tag' 
  13. ); 
  14.  
  15. // NOTICE! Understand what this does before running. 
  16. $result = post_tags_meta_box($post, $box); 
  17.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/meta-boxes.php  
  1. function post_tags_meta_box( $post, $box ) { 
  2. $defaults = array( 'taxonomy' => 'post_tag' ); 
  3. if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) ) { 
  4. $args = array(); 
  5. } else { 
  6. $args = $box['args']; 
  7. $r = wp_parse_args( $args, $defaults ); 
  8. $tax_name = esc_attr( $r['taxonomy'] ); 
  9. $taxonomy = get_taxonomy( $r['taxonomy'] ); 
  10. $user_can_assign_terms = current_user_can( $taxonomy->cap->assign_terms ); 
  11. $comma = _x( ', ', 'tag delimiter' ); 
  12. $terms_to_edit = get_terms_to_edit( $post->ID, $tax_name ); 
  13. if ( ! is_string( $terms_to_edit ) ) { 
  14. $terms_to_edit = ''; 
  15. ?> 
  16. <div class="tagsdiv" id="<?php echo $tax_name; ?>"> 
  17. <div class="jaxtag"> 
  18. <div class="nojs-tags hide-if-js"> 
  19. <label for="tax-input-<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_or_remove_items; ?></label> 
  20. <p><textarea name="<?php echo "tax_input[$tax_name]"; ?>" rows="3" cols="20" class="the-tags" id="tax-input-<?php echo $tax_name; ?>" <?php disabled( ! $user_can_assign_terms ); ?> aria-describedby="new-tag-<?php echo $tax_name; ?>-desc"><?php echo str_replace( ', ', $comma . ' ', $terms_to_edit ); // textarea_escaped by esc_attr() ?></textarea></p> 
  21. </div> 
  22. <?php if ( $user_can_assign_terms ) : ?> 
  23. <div class="ajaxtag hide-if-no-js"> 
  24. <label class="screen-reader-text" for="new-tag-<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label> 
  25. <p><input data-wp-taxonomy="<?php echo $tax_name; ?>" type="text" id="new-tag-<?php echo $tax_name; ?>" name="newtag[<?php echo $tax_name; ?>]" class="newtag form-input-tip" size="16" autocomplete="off" aria-describedby="new-tag-<?php echo $tax_name; ?>-desc" value="" /> 
  26. <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" /></p> 
  27. </div> 
  28. <p class="howto" id="new-tag-<?php echo $tax_name; ?>-desc"><?php echo $taxonomy->labels->separate_items_with_commas; ?></p> 
  29. <?php elseif ( empty( $terms_to_edit ) ): ?> 
  30. <p><?php echo $taxonomy->labels->no_terms; ?></p> 
  31. <?php endif; ?> 
  32. </div> 
  33. <div class="tagchecklist"></div> 
  34. </div> 
  35. <?php if ( $user_can_assign_terms ) : ?> 
  36. <p class="hide-if-no-js"><button type="button" class="button-link tagcloud-link" id="link-<?php echo $tax_name; ?>" aria-expanded="false"><?php echo $taxonomy->labels->choose_from_most_used; ?></button></p> 
  37. <?php endif; ?> 
  38. <?php