显示后端所有自定义帖子的标题列表


Show a list of titles of all the custom posts in backend

在我的Wordpress主题中,有一个名为" slider "的自定义帖子类型。

因此,我需要将所有滑块放在"主题选项"页面中的选择框中。因此,用户可以选择要显示的滑块。

如何做到这一点?

没关系,我自己找到了

<?php 
    $type = 'sliders'; // Whatever the post type
    $args=array(
      'post_type' => $type,
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
//Check if the there are posts                                    
if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
       <select>
         <option><?php the_title(); ?></option>
       </select>
<?php
      endwhile;
}
wp_reset_query();  // Restore global post data stomped by the_post().
?>