register_post_type
is recommended to be used in init
action hook. So, get_post_types
should be used in an action after init
. Hooking in init
with a very high priority, 999 or greater, should also work in almost every situation but it is safer to use a later action hook.
Example:
add_action('wp_loaded', function(){
$post_types = get_post_types( array( 'public' => true ), 'names' );
var_dump($post_types);
});
In admin section you can use admin_init
, which run after init
:
add_action('admin_init', function(){
$post_types = get_post_types( array( 'public' => true ), 'names' );
var_dump($post_types);
});
Related Posts:
- Use register_post_type() to modify an existing post type
- Load a script just to custom post type in admin
- Placing a Custom Post Type Menu Above the Posts Menu Using menu_position?
- Loading External Scripts in Admin but ONLY for a Specific Post Type?
- Customize Edit Post screen for Custom Post Types?
- Filter by custom field in custom post type on admin page
- Showing User’s Post Counts by Custom Post Type in the Admin’s User List?
- Merge two custom post types into one admin page?
- Custom post type pagination 404 fix?
- Remove the “View” Link in Post Admin
- Multiple custom post types under one admin menu
- How can I change the admin search posts fields?
- Custom post type: Add “Edit | Quick Edit | Trash | View” links to date (if title is not shown in column)?
- Per Post Type Revision Numbers
- Get list of all registered post types slugs
- Admin Area Custom Type Search By Meta Fields Without Title & Content
- Add “Last Edited by” column to custom post type list table
- How can I filter posts by post_parent in the admin?
- Filter custom post types in admin not working
- Custom post type admin search
- WP_Query ignores post_type in category view
- Ordering posts by custom taxonomy in admin area
- Create a dropdown with Custom Post Types as option in admin
- How to add custom columns to Custom Post Type admin screen
- How to Make an admin_notices Message That Disappears Once the User Leaves That Particular Page?
- Filter admin columns by custom post field value
- Is it OK to move admin menu items?
- How to get only posts, pages and custom post types in WordPress
- Prevent reload confirmation after AJAX save
- Filter by custom Field for Custom post type Admin Listing
- jQuery UI in Admin (Best Practice?)
- How do I implement custom fields without using any plugins?
- Admin Post Update Redirection to Posts Screen
- Exclude add_filter from the admin
- custom post types don’t appear in RSS
- Renaming Menu Item within Admin Menu Section for a Custom Post Type?
- Better to use a post type archive, page template, or shortcode for generating a highly configurable CPT archive?
- Custom Post type sort order not working in the admin area
- Custom admin columns for ALL custom post types
- How to get search results in the backend admin on a custom post type?
- Add custom column to custom post type overview in backend
- Adding a term name from a custom taxonomy assigned to a post link displayed by a wp_query loop based on another taxonomy
- Unable to filter on field on edit.php page
- How to Change the Title of a Meta Box on a Specified Custom Post Type? [duplicate]
- Registered Post Type Isn’t Showing in Admin Menu
- No results searching custom post type in admin panel
- How to add post_author column to custom post type
- Adding help information to custom post edit page
- Only Show an Author Their Custom Post Types
- Actions that Run on Admin Edit Page Load After Posts Are Queried
- Custom Post Type and taxonomies’s labels localization not working
- Change admin post thumbnail size for custom post type only
- Filters post in admin with dropdown select, custom post type
- Admin List Dynamic Heading
- How can I add a column in the wp_list_table of the admin area?
- Show admin help message across custom post type parent and child posts
- How to show custom (checkbox) field value in admin post list?
- WordPress User Roles, Custom Post Types, and Admin views
- Settings page above CPT page in admin section
- How to search CPT’s by meta query from the admin dashboard?
- Add theme options to custom post type admin pages [closed]
- Using WPAlchemy metabox values in another metabox
- Custom post admin filtering by post meta (the date)
- Admin Column Text Positioning
- Add text to wordpress admin ‘Add Post’ edit
- Changing ‘view’ link for custom post type on list post screen?
- Sort admin area by custom Event Date field
- How can I change the title of an Add New page in Admin for custom post type
- How to customize admin posts based on the user who is logged in
- Set a default category – if the user didn’t select one- before creating a post
- Multiple post type queries (with specific arguments for each)
- How to retrieve a custom post’s capability?
- Add html to cpt main page / admin edit.php
- Use get_post_types to query only custom posts types
- How can I create a custom meta box to add an mp4 video to a page?
- WP_Query | ‘post_type’ doesn’t work
- Remove rows in the manage post/page view
- Is there a way to have the view link on manage posts page to open in a new window or tab?
- Access $post object when adding custom columns to list table
- How to only show posts assigned to current user, only in certain post types
- Add acf field in title (admin table)
- Adding HTML tags or css classes to admin columns
- Create a page that will be used to create a custom post type
- child of post type (custom)
- Customize my custom taxonomy table in Admin panel
- Get parse_query filter to return slug instead of id
- How would I get a list of posts from a custom post type
- 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)?
- Prevent users from changing post status
- Why does ‘exclude_from_search’ exclude a custom post type from WP_Query?
- How to add post type in masonry posts elementory widget
- Display read only info on admin, custom post page
- Custom Plugin w/ Custom Post Types – Custom Posts Are Showing at all Privilege Levels – Is this possible to adjust?
- Quering array of post types & pagination. Articles are repeating sometimes on different pages
- How to set the Screen Options for Users in the Admin Panel?
- Issue displaying multiple TinyMCE editors with WPAlchemy
- Admin menu link with variable
- custom taxonomy not return in the code
- Custom post type REST api 404: Updating failed. No route was found matching the URL and request method
- How to set up a private custom post type that is accessible in the administrative dashboard?