Return to Snippet

Revision: 46282
at May 16, 2011 22:38 by hugosolar


Initial Code
function select_custom_posts($selected){
		
		$out.='<select name="'.$this->get_field_name('ctype').'" >';
		$out.='<option value="">Seleccione un tipo</option>';
		
		$args=array(
		  '_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;
		
	}

Initial URL

                                

Initial Description
this creates a function inside a widget object to create a dropdown menu with all the custom post types created in wordpress functions.

Initial Title
Get custom post types inside a wordpress widget

Initial Tags
post, wordpress

Initial Language
PHP