WP-Helper dropdownCustomPostType einbauen
/**
* Renders an DropDown for Custom Post Types.
*
* @param string $id The id / the name of the select.
* @param string $postType The name of the custom post type.
* @param integer $selected The ID of the selected post.
* @param string $unselected The text for "unselected".
*
* @return void
*/
public static function dropdownCustomPostType($id, $postType, $selected = 0, $unselected = 'nicht gewählt') {
$posts = get_posts(
array(
'post_type' => $postType,
'post_status' => 'publish',
'posts_per_page' => -1,
'supress_filters' => FALSE,
)
);
?>
<select name="<?php echo $id; ?>" id="<?php echo $id; ?>">
<option value="0"><?php echo $unselected; ?></option>
<?php foreach ($posts as $post) : ?>
<option value="<?php echo $post->ID; ?>" <?php if ($post->ID === $selected) : ?>selected="selected"<?php endif; ?>><?php echo $post->post_title; ?></option>
<?php endforeach; ?>
</select>
<?php
}