0

I have a custom post type "Events".

In Events, I have a custom field for "Place" which is a dropdown list.

Is there a way to edit the contents of the dropdown list through the admin panel or is changing the code itself the only way?

  • What are you using to enable the custom field? Plugin? – joshrathke Aug 15 '13 at 5:08
  • I didn't use any plugin. I hard coded it if that's what you mean. – user36643 Aug 15 '13 at 5:09
  • What kind of content do you want to populate it with from the dashboard? – joshrathke Aug 15 '13 at 5:09
  • Hmm, I'm note sure I follow. In my Events post type, there is a field which lets me choose a Place/Venue. This field is a dropdown list. Example: USA, Italy, Australia, and China. However, the client wants the ability to edit/change the contents of the dropdown list through the admin side. – user36643 Aug 15 '13 at 5:13
0

I think this is really what taxonomies are for, so if a custom taxonomy won't work, you could always still create the custom taxonomy and populate the drop down with the taxonomy. This would allow the user to create new terms via the taxonomy. There is a plugin called Meta Box, and it makes stuff like this a breeze!

Update After commenting with you back and forth below, I think what you are really looking for is just a custom taxonomy that will allow the user to add, subtract, and apply terms to a post or page. A taxonomy is one of those boxes on the right side of the post or page creation screen like "tags" or "categories" that allows a user to add terms to a post, which allow the posts to be searchable, more organized and much more filterable.

If you want you can just copy paste this into your functions.php file to create a new taxonomy and append it to the posts and pages admin screen. This is straight from the WP documentation.

// hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_places_taxonomies', 0 );

// create two taxonomies, places and writers for the post type "book"
function create_places_taxonomies() {
    // Add new taxonomy, make it hierarchical (like categories)
    $labels = array(
        'name'              => _x( 'Places', 'taxonomy general name' ),
        'singular_name'     => _x( 'Place', 'taxonomy singular name' ),
        'search_items'      => __( 'Search Places' ),
        'all_items'         => __( 'All Places' ),
        'parent_item'       => __( 'Parent Place' ),
        'parent_item_colon' => __( 'Parent Place:' ),
        'edit_item'         => __( 'Edit Place' ),
        'update_item'       => __( 'Update Place' ),
        'add_new_item'      => __( 'Add New Place' ),
        'new_item_name'     => __( 'New Place Name' ),
        'menu_name'         => __( 'Place' ),
    );

    $args = array(
        'hierarchical'      => true,
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'places' ),
    );

    register_taxonomy( 'places', array( 'post', 'page' ), $args );
}

If you would like to change the functionality to a more "tag" like function, then simply changed the hierarchical setting to false.

'hierarchical'      => true,

You really should be using taxonomies to perform this function rather than a custom drop down box. Should your client want to expand upon the functionality, this is going to make it very easy to do so in the future.

  • I don't think that plugin is compatible with WP 3.6? It's not showing – user36643 Aug 15 '13 at 5:49
  • It's completely compatible, I am running it on several blogs that are all stable and running 3.6. Can you elaborate on what you mean by "not showing"? – joshrathke Aug 15 '13 at 5:55
  • Hmm. Where can I add meta boxes? When I installed, I went to add a new post, but nothing has changed. – user36643 Aug 15 '13 at 6:07
  • Did you read the documentation? You have to code the original meta boxes, but you can easily create one that pulls from a taxonomy that your client can add terms to in the dashboard. It saves you a lot of work in terms of automatically populating the box. – joshrathke Aug 15 '13 at 6:25
  • Okay. But how exactly do I change the contents from the admin? I don't quite get that part. Thanks – user36643 Aug 15 '13 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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