/ Published in: PHP
this creates a function inside a widget object to create a dropdown menu with all the custom post types created in wordpress functions.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function select_custom_posts($selected){ $out.='<select name="'.$this->get_field_name('ctype').'" >'; $out.='<option value="">Seleccione un tipo</option>'; '_builtin' => false ); $post_types=get_post_types($args,'names'); foreach ($post_types as $post_type ) { $selec=($selected==$post_type)?'selected':''; $out.= '<option value="'.$post_type.'" '.$selec.'>'. $post_type. '</option>'; } $out.='</select>'; echo $out; }