How to get the custom post type from an archive page?
In my website I have three custom post types: scripts, scenes and plugins. When visiting the archive page of a single post type (i.e. by going to mysite.com/plugins) you correctly see all the posts of that type.
In archive.php, how can I find out which custom post type the user is looking at right now?
I tried the following:
<?php global $post; $postTypeLabels = get_post_type_labels(get_post_type_object($post)); echo var_export($postTypeLabels); ?>
But I’m getting the this:
Post name is stdClass::__set_state( array( 'name' => 'Posts', 'singular_name' => 'Post', 'add_new' => 'Add New', 'add_new_item' => 'Add New Post', 'edit_item' => 'Edit Post', 'new_item' => 'New Post', 'view_item' => 'View Post', 'search_items' => 'Search Posts', 'not_found' => 'No posts found.', 'not_found_in_trash' => 'No posts found in Trash.', 'parent_item_colon' => NULL, 'all_items' => 'All Posts', 'menu_name' => 'Posts', 'name_admin_bar' => NULL, ) )
I’m guessing that, since I am in an archive page, the $post is not correct.
P.S. I know that I can create archive-plugins.php for the plugins archive. Unfortunately, I have installed a theme that, as far as I know, kinda prevents that. So this is not an option.