Post types in WordPress are not saved some where, they are registered everytime you request a page.
So to get all post types, you have to wait untill all post types are registered.
Normally, all post types are registered before the hook wp_loaded
is fired.
So change your code in something like this:
add_action( 'wp_loaded', 'my_get_all_types' );
function my_get_all_types() {
// if you want only custom post types use '_builtin'=> false in the arguments array
// 2nd argument should be 'objects' not 'object'
$cpts = get_post_types( array( '_builtin'=> false ), 'objects');
var_dump($cpts);
}
Related Posts:
- New post status for custom post type
- How do I set the default admin sort order for a custom post type to a custom column?
- Delete all posts of a custom post type—efficiently
- Adding Custom Post Type Counts to the Dashboard
- Get Custom Taxonomy ID within loop
- Custom Post Types not showing on Custom Taxonomy archive page
- Using Templates with Custom Post Type UI
- WordPress Custom Post Type Admin Page really slow
- is_singular() not working if called via callback function of admin-ajax.php
- Creating a gallery of featured images from custom post type
- Taxonomy terms with edit/filter link in wp-admin, in the list of custom posts
- Search everything (posts, pages, tags, cpt, meta)
- Reslug a Custom Post Type
- front end radio custom taxonomy with custom post type
- How to add meta boxes(repeater fields) from WordPress back end?
- Displaying Meta Box Image
- Custom post type: No posts found even if counter has a count
- Admin List Dynamic Heading
- Beginner question: Accessing functions.php through admin web interface in order to import custom post types?
- How can i list custom post type categories?
- Query Custom Post by Category
- WP_Query and using a variable for ‘cat’=> in the args array = WP Bug?
- Custom post query by taxonomy
- Create second custom 404 page for selected post type
- Custom post type routing with hierarchy
- Role Capabilities: Add New Ones?
- Sub-Sub-Blogs — creating and importing content into a custom sub-type
- How does register_post_type know how and which function to use from the add_action function?
- WordPress Create Post from front-end
- Custom post type with slug for plural (archive) and for single
- Add category in post type dynamically
- Shortcode insertion in tab
- Use regular category with custom post types
- Change Featured Image / Thumbnail CMS Description
- add custom field to custom post type
- How to convert custom post type based list to a dropdown list?
- Custom post type search using $_SESSION and pre_get_posts
- can’t see custom post content filtered under “mine” filter in admin panel
- read_post meta capability for anonymous users
- Custom template Page 2 not working
- Problems with image size on the server WordPress
- Search by tag name and category
- Moving meta boxes in admin
- Can we create a custom post template for a specific page template
- Why is get_pages() returning a boolean?
- Settings API – save multiple tabs at once
- How to create multiple editor?
- Page Template Dropdown For Custom Post Types
- How to include category name/id in wp_query for retrieving “custom post type” from a particular category?
- Include custom post type custom taxonomies in Categories widget
- Sort custom post type by most current date picker
- Using menu_position to add two entries between Dashboard and Posts
- custom permalink for post only not custom post types
- How to manage selected post-formats in custom post type
- Remove default WYSIWYG editor without removing custom fields editors
- File sharing platform for user contributions? [closed]
- post_content is stripping HTML when adding a new post? [closed]
- Querying a custom post type, but not show duplicates
- Save CTP post meta different values each day without overwriting previous values
- Changing CPT slug and taxonomy already registered in parent theme
- Show post count number assigned to custom taxonomy
- Update ACF fields on a frontend form? [closed]
- Ignores post_type when no results
- Page-CPT.php redirects to archive or single.php
- Sanitaizing Select Optin For Custom Post Type Metabox in WP
- Printing errors during save custom post type
- Creating on-page options for Custom Post Type
- Check when the post type changes, and display content
- Is possible register two archive pages for single custom post type?
- Include “Scheduled” (“Future”) Posts in WordPress Post Navigation ( previous_post_link, next_post_link ) for a Specific Custom Post Type
- WP_Query to display number of custom post type filtered (order by) taxonomy
- Where is get_post_meta value located?
- 2 modal windows with ACF content on Archive page
- Custom post type single page uses the right template in preview mode but shows a different template after being posted
- Custom Post Type – Display all, wrap in groups of 3
- Showing Custom Post Type with his templates on a custom page template
- Display post in sequence from different custom post_type
- Sort loop by custom field from different post type
- Custom post meta box as a sub form
- Custom post edit page permalink links to edit page rather than the post
- Custom meta box data not saving
- Custom post type rewrite and wp_pagenavi interfering with each other
- WordPress loop, show only one post per custom field
- Getting list of Categories for Custom Post Types
- Adding Information To All Posts Screen
- get children from current variable (taxonomy) via shortcode
- Show Templates in Custom Post Type Editor
- Custom meta-box for all custom post types
- Retrieve a specific category of posts when using a custom post type
- WordPress Load more posts by ajax not working
- Multiple while loops not functioning [closed]
- Listing all custom post types using a specific term on the said term’s template page, in groups
- Ideal top-level slug methods
- How can I make a custom post type that loops pages in a new dashboard page, each single page is a new dashboard page (all within the back-end)?
- taxonomies or categories w/custom post
- Require Custom Taxonomy for Custom Type
- Two blogs on same WP website
- Save post_parent in a custom post type
- Get post from custom post type that title is like custom string [closed]
- Taxonomy Archive URL + Template