I am making a WordPress plugin and hit a rough point. I'm trying to make it so a user can select from all their post types, including custom post types. The code I have below shows the post, page, and attachment post types in a dropdown in the WordPress admin.
<?php
$args = array(
'public' => true,
'_builtin' => true
);
$output = 'names'; // names or objects, note names is the default
$operator = 'and'; // 'and' or 'or'
$post_types = get_post_types( $args, $output, $operator );
echo '<select name="custom-post-types">';
foreach ( $post_types as $post_type ) {
echo '<option value="'. $post_type.'">' . $post_type . '</option>';
}
echo '</section>';
?>
I understand how users could use their functions.php to hook in their custom post types, but I am trying to avoid that pain for them and rather have the plugin grab all theirs automatically. I've tried looking at other plugins and searching but the search results aren't relevant for this and other plugins were over my head for figuring out.
Appreciate any help, thanks.