Custom post types can only be registered on the init
hook. So if you’re trying to get the post types before the init
hook, you will only ever get the built-in ones.
To get custom post types, you need to use a hook after init
, or later on init
than the custom post types were registered.
function wpse_func() {
$args = array(
'public' => true,
'_builtin' => false,
];
$post_types = get_post_types( $args );
}
add_action( 'init', 'wpse_func', PHP_INT_MAX );
//* Or
add_action( 'wp_loaded', 'wpse_func' );
Related Posts:
- How do I safely change the name of a custom post type?
- How to get custom post type post id from slug?
- why doesn’t the_content() work in this {single-custom_post_type.php} page?
- Custom Post Type Menus
- Custom Taxonomy Template Post List with Sort Order
- Custom post types vs post formats : future-proofing – is one less “future proof” than another?
- Hiding Custom Post Type from Google?
- Display Custom Post Type Fields
- Get monthly archives for custom post type
- Taxonomy page returns 404 page not found
- How to get dynamically custom post type that are under a certain category
- Single Page WordPress CSS and JS links
- WordPress query by multiple Custom fields and order by date
- Display taxonomy term only if there’s a value
- Custom/separate categories for custom post type
- Correct way to use get_template_part() and get_post_format() with custom post types?
- How to delete all posts from a custom post type?
- Query custom post types and a specific page?
- Custom Post Type Pagination & duplicate posts
- Multisite custom post type’s single page 404
- using add_role function to make some users to create a selected type post
- Custom Post Type and API REST is not working
- Display custom field of specific post where post title matches variable
- How to search for many post types?
- How to retrieve category NAME instead of ID in a function with a taxonomy custom field?
- Change URL of posts and also Custom Post Type
- Show Different Header on a Specific Post ID
- Diplay content from custom type as widget or sidebar?
- Custom post type and taxonomy slug issue
- WooCommerce product search titles only
- Related posts in all categories of current post (custom post types)
- Custom Post Type template stored in plugin folder not showing in post attributes dropdown
- Custom template won’t load for a custom post type (custom permalinks used)
- Change Slug in URL of Posts of custom post type
- Add a button or image button that calls wp functions in the wp-admin
- Get parse_query filter to return slug instead of id
- Help with Elementor Pagination CPT archive 404 problem
- Custom Post Type + ACF and performance [closed]
- is_post_type_archive is false when I pass GET parameters in the URL
- Adding custom post type to count in category
- Custom Permalinks with CPT and Hierarchical Taxonomies
- Canonical url differs from custom post type archive URLs
- Custom post type template but
- Ignoring slug capitalization on rewrite rule for custom post type archive page
- How to sort posts in a custom post type by title in ascending order by default?
- custom post type vs. conditionally displaying meta boxes for specific terms?
- data-type=”” … needed post tags stripped of characters
- Bootstrap accordion looping through posts incorrectly
- Use Pages for Custom Post Type
- Issue on Working with Metabox – Checkbox to enable Sale Items
- Search Filter CPT, Custom Loop
- Get post ID of either existing post or new post
- Create a simple Testimonial page
- How to call a post’s metadata in shortcode.php?
- Revert to previous dropdown options after change
- next page with custom post
- What should I learn to develop event management in wordpress? [closed]
- wp-includes does not contain a feed template
- Why is the output of a call to the_excerpt different when the call seems to be identical?
- Implement location at wordpress post via custom taxonomies?
- What is the best way to manage small blocks of content on my home page?
- Only looping through pages that have children or subpages
- Two-way synchronizing of a post type among multisite blogs
- How to sort WP_Query by a custom text field (written as a date dd/mm/yyyy)
- Custom post type rewrite url structure with taxonomy and sub taxonomy
- list articles in admin showing nested categories or slugs?
- How to upload two input files [closed]
- Custom Post Type with Category Separate
- URL issue retrieving Custom Post Types using Backbone JS API
- How can I add a URL link to my post type?
- Custom metabox with image gallery upload that won’t attach images to post
- order custom post type posts by custom date
- Foreach result into WP_query
- Standard Page Child of CPT Not Found (404)
- Custom Post Type parent/child relationship rewrite rules for permalinks
- Related posts by taxonomies does not work , what could be the reason?
- Display first post of a term in taxonomy template
- How to transfer categories (default) to custom taxonomy?
- Query posts based on user preferences
- call a function when insert and update a custom post type
- How can I remove “Add new” button on custom post type
- Search attachments in custom post type only
- Same permalink structure for all post types?
- How to have working breadcrumbs with several taxonomies associated with a custom post type
- Custom Post type archives / categories give 404
- Sorting on Taxonomy in archive page
- Front-end form submission not creating post
- Pages displays correctly but returning a 404 error in http header.
- Custom options for a Custom post type
- Custom loop won’t work, can’t find problem
- link posts to custom post type
- Query by post type or category
- Most appropriate way to display CPT’s by children terms of custom taxonomies while retaining desired permalink structure?
- See the process of creating a taxonomy and tell me where I made a mistake
- Google Analytics Dashboard for WP in Custom Column
- CPT Template Option to Top
- Navigation won’t update to show full path to single post
- Register_post and add_menu & add_submenu conflict?
- Custom post type Premalinks main page and details page
- Two custom post type relations