Posted By

hugosolar on 05/16/11


Tagged

post wordpress widget types custom


Versions (?)

Get custom post types inside a wordpress widget


 / 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.

  1. function select_custom_posts($selected){
  2.  
  3. $out.='<select name="'.$this->get_field_name('ctype').'" >';
  4. $out.='<option value="">Seleccione un tipo</option>';
  5.  
  6. $args=array(
  7. '_builtin' => false
  8. );
  9.  
  10. $post_types=get_post_types($args,'names');
  11. foreach ($post_types as $post_type ) {
  12. $selec=($selected==$post_type)?'selected':'';
  13. $out.= '<option value="'.$post_type.'" '.$selec.'>'. $post_type. '</option>';
  14. }
  15.  
  16. $out.='</select>';
  17. echo $out;
  18.  
  19. }

Report this snippet  

You need to login to post a comment.