Leave a Reply

1 comment

  1. Here is what I discovered and use, maybe it will help you:

    function custom_posttype_dropdown($name, $selected)
    {       
        $out = "";
        $posts = get_posts(
            array(
                'post_type'  => 'bctap_templates',
                'numberposts' => -1
            )
        );
        if($posts )
        {
    
            $out = '<select name="'.$name.'" ><option>Select a Template</option>';
            foreach( $posts as $p )
            {
                if ($p==$selected)
                {
                    $selected = "selected = 'selected'";
                }
                else
                {
                    $selected = "";
                }
                $out .= '<option value="' . $p->ID . '" '.$selected.'>' .$p->post_title  . '</option>';
            }
            $out .= '</select>';
        } 
        else
        {
            $out = '<select name="'.$name.'" value="x" ><option>Select a Option</option>';
            foreach( $posts as $p )
            {               
                $out .= '<option value="x" '.$selected.'>None Created Yet.</option>';
            }
            $out .= '</select>';
        }
        return $out;
    }
    
    //to call
    echo custom_posttype_dropdown($name, $selected);