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
- Merge two custom post types into one admin page?
- 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)?
- Admin Area Custom Type Search By Meta Fields Without Title & Content
- How can I filter posts by post_parent in the admin?
- Custom post type admin search
- Ordering posts by custom taxonomy in admin area
- 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?
- Is it OK to move admin menu items?
- 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?
- Exclude add_filter from the admin
- Better to use a post type archive, page template, or shortcode for generating a highly configurable CPT archive?
- Custom admin columns for ALL custom post types
- Registered Post Type Isn’t Showing in Admin Menu
- 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
- Custom Post Type and taxonomies’s labels localization not working
- 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?
- How to search CPT’s by meta query from the admin dashboard?
- Add theme options to custom post type admin pages [closed]
- Custom post admin filtering by post meta (the date)
- Admin Column Text Positioning
- Changing ‘view’ link for custom post type on list post screen?
- Sort admin area by custom Event Date field
- Multiple post type queries (with specific arguments for each)
- WP_Query | ‘post_type’ doesn’t work
- How to only show posts assigned to current user, only in certain post types
- 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
- A simple script to allow sorting of custom posts in admin?
- Notify admin on new submit
- On update or create post redirect to current post position in list
- Limit amount of posts made within a custom taxonomy
- Options page – dropdown of users
- No Permission to add new Page, Post or CPT with Admin role
- Filtering posts list table
- get_the_post_thumbnail_url(‘full’) returns empty from custom post type
- single-{post_type}.php not working
- Can I change my post type to anything and my site still work?
- How to group navigation items in the admin panel
- Custom filter for main search: how to exclude specific post_type from search results
- Plugin or method of allowing user to rearrange custom post types with drag and drop?
- get_post_types – exclude multiple post types by name
- Insert Custom Post Types
- Custom Post Type – Support “author” only for admins
- Remove taxonomies using register_post_type_args
- post_type internal ID?
- Dynamic pages for linked categories and content
- Add ‘page template’ column to dashboard for CPTs
- How to copy a custom field from the user’s CPT to the user’s normal posts
- Post Type => Any conundrum
- Require custom post type if is_admin() – template doesn’t show up?
- Multiple custom post types on same admin page
- using the loop in custom meta is messing up ‘add new’ post type
- Metaboxes inside Tab
- How can I put content before my custom post type default pages?
- Custom Post Type Single Page is not working
- How we can create menu from Appearance > Menu and use as a add-submenu-page for admin menu?
- Is there any filter to add a custom attribute to the tag in admin panel?
- Get all post types that supports tags
- custom post type single page not found after aotumatic publish By the author’s robot
- Help Adding filter to Add Media button for custom post type
- How to mix 2 kinds of post types
- Delete all custom posts then upload a new CSV of events
- Change Custom Post Type to Post + Category
- Pagination in wp-admin for CPT
- Shortcode in excerpt
- Custom post type post_type_link gives “page not found” on any other custom post type
- Create an administation subpage containing posts in a certain category
- How to set a default CPT template and create post attribute´s display rules?
- custom post permalink
- Pulling in Related Posts based on Post Type array
- Customising the admin columns for a custom post type, but now most of the built in categories don’t display?
- Admin menu post type
- Custom Post Type Causing Admin Sidebar UI Issue
- How to change the default orderby from “Date” to e.g. “Title” or my custom column in content type records list in admin?
- Change column of row action (Quick Edit) links in WP_List_Table
- Collection of fields in a single post
- 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?
- 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
- Issue displaying multiple TinyMCE editors with WPAlchemy
- Admin menu link with variable
- Custom post type REST api 404: Updating failed. No route was found matching the URL and request method