当从其他选择列表中选择任何帖子类型时,如何列出选择列表中的所有帖子(如果有)

时间:2014-10-03 10:08:30

标签: php wordpress

我成功地将所有帖子类型都添加到了选择中       选择帖子类型

<select name="meta-select" id="select_post_types" class="form-control">  
    <?php foreach ( $post_types as $post_type ) { ?>
    <option value="<?php print $post_type; ?>"> <?php print $post_type; ?> </option>
    <?php } ?>
</select>

但是,当管理员从顶部选择中选择时,我想填充所有选定帖子类型的帖子。

遵循第二个选择

<select name="meta-select" id="select_post" class="form-control">  
    <option value=""> </option>';

</select>

1 个答案:

答案 0 :(得分:0)

<?php
$args = array(
   'public'   => true,
   '_builtin' => false
);

$output = 'names'; // names or objects, note names is the default
$operator = 'and'; // 'and' or 'or'

$post_types = get_post_types( $args, $output, $operator ); 
?>
<select name="meta-select" id="select_post" class="form-control">  
    <?php
    foreach ( $post_types  as $post_type ) {

       ?>
       <option value="<?php print $post_type; ?>"> <?php print $post_type; ?> </option>

       <?php
    }

    ?>
</select>