Display all WordPress article types in a drop-down list

WordPress comment four hundred and thirty-four Reading mode

All WordPress article types, including custom article types, are displayed in a drop-down list.

 <? php $args = array( 'public' => true, ); $post_types = get_post_types( $args, 'objects' ); ?> <select class="widefat" name="post_type"> <? php foreach ( $post_types as $post_type_obj ): $labels = get_post_type_labels( $post_type_obj ); ?> <option value="<?php echo esc_attr( $post_type_obj->name ); ?> "><?php echo esc_html( $labels->name ); ?></ option> <? php endforeach; ?> </select>

 

 Display all WordPress article types in a drop-down list

Most of the articles on this site are original and used for personal learning records, which may be helpful to you, for reference only!

 weinxin
My Wechat
WeChat copied
Copyright Notice
Please indicate the source and link of the original article reprinted on this site. Thank you for your cooperation!
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 
 Robin
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 anonymous

Comment

Anonymous netizens
 :?:  :razz:  :sad:  :evil:  :!:  :smile:  :oops:  :grin:  :eek:  :shock:  :???:  :cool:  :lol:  :mad:  :twisted:  :roll:  :wink:  :idea:  :arrow:  :neutral:  :cry:  :mrgreen:

Drag the slider to complete validation