You can get a list of post types with the get_post_types()
function:
$post_types = get_post_types();
In your case you’ll want to set the second $output
parameter to names
(since that’s what you need to pass to the post_type
argument), and you’ll probably want to set the $args
in the first argument so that only public post types are returned, otherwise you could end up with weird stuff like menu items and revisions:
$post_types = get_post_types( [ 'public' => true ], 'names' );
However, it looks like you’re just looking for a specific post based on the ID. If that’s the case, then you don’t need post types or a query at all. Just pass the ID to get_post()
:
$post = get_post( $id );