Dropdown list of a custom post type

You’ll need to use get_posts and roll your own drop down.

Something like this (somewhere in functions.php):

<?php
function wpse34320_type_dropdown( $post_type )
{
    $posts = get_posts(
        array(
            'post_type'  => $post_type,
            'numberposts' => -1
        )
    );
    if( ! $posts ) return;

    $out="<select id="wpse34320_select"><option>Select a Doctor</option>";
    foreach( $posts as $p )
    {
        $out .= '<option value="' . get_permalink( $p ) . '">' . esc_html( $p->post_title ) . '</option>';
    }
    $out .= '</select>';
    return $out;
}

Then in your template…

<?php echo wpse34320_type_dropdown( 'doctors' ); ?>

Leave a Comment

tech