I'm looking to create a dropdown in the post edit screen which contains 3 already existing tags. What's the easiest way of doing this?

Basically all I'm looking for is a simple drop down which adds one of the following tags to the post itself; 'beef-stew', 'pea-soup' & 'chili'. I'd also like 'beef-stew' to be the default.

Thank you in advance

EDIT: As I don't want the user to be able to display more than 1 of these 3 categories at any time, and have to option to easily change which one as they please, tags might not be the best solution? Would I be better off creating a custom taxonomy ('food')? They will basically be used to change the way a post is displayed on the front page of the website.

2 Answers 2


I followed this handy guide and it worked a treat:



Create Custom Post Type

function create_product()
   $labels = array(
    'name'               => _x( 'Product', 'post type general name', 'stacy' ),
    'singular_name'      => _x( 'product', 'post type singular name', 'stacy' ),
    'menu_name'          => _x( 'Products', 'admin menu', 'stacy' ),
    'name_admin_bar'     => _x( 'Product', 'add new on admin bar', 'stacy' ),
    'add_new'            => _x( 'Add New', 'product', 'stacy' ),
    'add_new_item'       => __( 'Add New Product', 'stacy' ),
    'new_item'           => __( 'New Product', 'stacy' ),
    'edit_item'          => __( 'Edit Product', 'stacy' ),
    'view_item'          => __( 'View Product', 'stacy' ),
    'all_items'          => __( 'All Product', 'stacy' ),
    'search_items'       => __( 'Search Product', 'stacy' ),
    'not_found'          => __( 'No Product found.', 'stacy' ),
    'not_found_in_trash' => __( 'No Product found in Trash.', 'stacy' )
   $args = array(
    'labels'             => $labels,
    'description'        => __( 'Description.', 'Add New Product on stacy' ),
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => true,
    'query_var'          => true,
    'rewrite'            => array( 'slug' => 'product' ),
    'has_archive'        => true,
    'hierarchical'       => false,
    'menu_position'      => 100,
            'menu_icon'          =>'dashicons-cart',
    'supports'           => array( 'title', 'editor', 'author', 'thumbnail','comments','capabilities' ),
            'taxonomies'         => array('product_category','product_tag')
    register_post_type( 'product', $args );
 add_action( 'init', 'create_product' );

Create Custom Metabox and Display meta value on edit post

  function add_product_details_meta_box()
   global $wpdb;
   global $post;
   $custom = get_post_custom( $post->ID );
    <label>Short Description:</label><br />
    <textarea rows="5" name="short_description" class="width99"><?= @$custom["short_description"][0] ?></textarea>
    <label>Price:</label><br />
            <input type="text" name="price" value="<?= @$custom["price"][0] ?>" class="width99" />

    <label>Dimensions (in):</label><br />
            <input type="text" name="length" value="<?= @$custom["length"][0] ?>" class="s" placeholder="Length"/>
    <label>Shipping Lead Days:</label><br />
            <input type="text" name="ship_lead_days" value="<?= @$custom["product_ship_lead_days"][0] ?>" class="s" placeholder="Shipping Lead Days"/>
    <label>Commision:</label><br />
            <input type="text" name="commision_broker" value="<?= @$custom["commision_broker"][0] ?>" class="s" placeholder="Enter Your Commision Here"/>
  add_action( 'admin_init', 'add_product_meta_boxes' );

Update Post Meta

function save_product_custom_fields(){
 global $post;

 if ( $post )
   update_post_meta($post->ID, "short_description", @$_POST["short_description"]);
  update_post_meta($post->ID, "price", @$_POST["price"]);
  update_post_meta($post->ID, "length", @$_POST["length"]);
add_action( 'save_post', 'save_product_custom_fields' );
  • Can you just explain a little bit in addition to code
    – bravokeyl
    Jul 14, 2016 at 9:41
  • first code for create a custom post type second code for meta box that you want to some custom fields on your post type. Jul 14, 2016 at 10:02
  • last code for update meta box value on post meta Jul 14, 2016 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.