0

I have a custom post type Event. I also have custom meta boxes (e.g. a dropdown list for the speaker of that event). However, the list of speakers are hard coded by me, and the client wants to be able to add, edit, and remove the speakers from the admin part.

How do I do this?

2
  • how are you setting the meta box? with case and switch? Commented Aug 12, 2013 at 3:01
  • I have them in array and I indicate which pages the meta box will appear. Commented Aug 12, 2013 at 3:14

2 Answers 2

1
$items = get_posts( array (  
    'post_type' => YOUR_POST_TYPE,  
    'posts_per_page' => -1,
    'post_status' => 'publish' 
)); 

<select name="get-posts" id="get-posts"> 
            <option value="">Choose A Page</option>
            <?php   
        foreach($items as $item) {  
            echo '<option value="'.$item->ID.'"',$meta == $item->ID ? ' selected="selected"' : '','>'.$item->post_title.'</option>';  
        } // end foreach ?> 
</select>
Sign up to request clarification or add additional context in comments.

5 Comments

This code outputs the selected item in the dropdown, right? How do I do it so the admin can add, edit, and delete options / items in the dropdown menu?
the code actually outputs the ID - I was using it for a slider to link the page too but you can change the value to $item->post_title too. if you make a new custom post type then each time they add or remove the post type it will populate the dropdown
Can you expound on that more? Also I don't need to make a new custom post type or add or remove one.
if you dont want to do it that way - i suggest using repeatable fields. check out this tutorial
Thanks for this. Part 2, the part where it says "Manage Categories", I think this is the functionality I am looking for.
0

you can do it by custom metabox, here is the code form codex

register_taxonomy( 
  'speakers', 
  array( 'YOUR_POST_TYPE' ), 
  array( 
    'hierarchical' => true, 
    'labels' => array(
        'name'              => _x( 'Speakers', 'taxonomy general name' ),
        'singular_name'     => _x( 'Speaker', 'taxonomy singular name' ),
        'search_items'      => __( 'Search Speakers' ),
        'all_items'         => __( 'All Speakers' ),
        'parent_item'       => __( 'Parent Speakers' ),
        'parent_item_colon' => __( 'Parent Speakers:' ),
        'edit_item'         => __( 'Edit Speakers' ),
        'update_item'       => __( 'Update Speakers' ),
        'add_new_item'      => __( 'Add New Speakers' ),
        'new_item_name'     => __( 'New SpeakersName' ),
        'menu_name'         => __( 'Speakers' ),
    ), 
    'rewrite' => true 
  ) 
);

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.