WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have successfully pulled a custom post type through into a drop-down that is in a custom meta box. However, when displaying it on the front end I would like to also provide a link to the actual post, not just the name of the post. So I am guessing I need to save this as an array? Is this possible through a drop-down? Confused on how I should approach this. Any help is greatly appreciated.

Here is what I have so far:

// Add Meta Box To Select Overseeing Pastor
add_action('admin_init', 'ministry_select_add_meta');
function ministry_select_add_meta(){
    add_meta_box('ministry_select_post', __('Overseeing Pastor'), 'ministry_select_meta', 'ministry', 'side');

function ministry_select_meta( $post ) {
    $values = get_post_custom( $post->ID );
    $selected = isset( $values['pastor_select'] ) ? esc_attr( $values['pastor_select'][0] ) : '';
    wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
        <select name="pastor_select">
            $args = array(
                'post_type' => 'employee',
                'position' => 'pastor'
            $pastorList = new WP_Query($args); while ($pastorList->have_posts()) : $pastorList->the_post();
                $is_selected = (get_the_title() == $selected) ? 'selected="selected"' : '';
                echo '<option value="'.get_the_title().'" '.$is_selected.'>'.get_the_title().'</option>';
            endwhile; wp_reset_postdata();

add_action( 'save_post', 'ministry_select_save' );
function ministry_select_save( $post_id )
    // Stop If Autosaving
    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;

    // Stop If Nonce Can't Be Verified
    if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;

    // Stop If Unauthorized User
    if( !current_user_can( 'edit_post' ) ) return;

    // Make Sure Data Is Set Then Save      
    if( isset( $_POST['pastor_select'] ) )
        update_post_meta( $post_id, 'pastor_select', esc_attr( $_POST['pastor_select'] ) );
share|improve this question
up vote 2 down vote accepted

Quite simple. Instead of saving the post title, save the post ID, so in the front end you can extract all necessary info.
Like so: get_post( $the_saved_ID_value ); or get_permalink( $the_saved_ID_value );.

In you code, change this line:

echo '<option value="'.get_the_ID().'" '.$is_selected.'>'.get_the_title().'</option>';


share|improve this answer
This is actually what I ended up doing but forgot to post it. Appreciate the answer! Thanks. – ftntravis Feb 15 '13 at 21:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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