Your code looks good. However, you can try the followoing codes to get all custom posts
$args = array(
'public' => true,
'_builtin' => false,
);
$output="names"; // names or objects, note names is the default
$operator="and"; // 'and' or 'or'
$post_types = get_post_types( $args, $output, $operator );
foreach ( $post_types as $post_type ) {
echo '<p>' . $post_type . '</p>';
}
?>
you can also use a bunch of args to filter your result much. For details lists of args you can check the official WordPress Codex page: https://codex.wordpress.org/Function_Reference/get_post_types
Related Posts:
- How to get current get_post_types name?
- How to rewrite URI of custom post type?
- How to display only top level posts in loop via WP_Query?
- Multiple Custom Metabox Help
- flush_rewrite_rules on save_post Does Not Work on First Post Save
- Column sorting with emtpy meta values
- Add custom column to custom post type overview in backend
- Create sub single pages
- If on term-page -> get the current term?
- How Do I Use WP_Query to Run This Database Query as Search Result?
- Loading post content in FancyBox
- Should I change these content meta types before building complex archive page?
- Using a Custom Field instead of original title field but only for Custom Post Type
- Adding Custom Metaboxes to Custom Pages
- How to show custom taxonomy in the permalink?
- Edit/Customize the Single Page of a Genesis Sample Child Theme
- How to initialize PODS?
- wordpress custom post type remove duplicate menu item
- How to list custom post types?
- How to create A-Z index listing for custom post types?
- Custom post type search with slug in URL
- Creating select dropdown with parent-level custom post types
- CPT Group by Date metabox Value
- Query Custom posts of same taxonomy as the post itself
- Showing posts from different categories and from custom post type
- Editing a list of several fields
- Custom post type: check permissions and validate nonce
- Rewrites/query for multiple hierarchical custom post types
- Custom Post Type has_archive
- Taxonomy/Custom post type structure suggestion on a movie site
- Get Tags by specific Category of Custom Post Type
- How to sort the admin area of a WordPress custom post type by a custom field
- Edit the_content() function so to add a div wrapper
- Custom Field values not Showing in Edit Page of Custom Post Type
- Display custom post types in wp_list_pages
- How to list tags from custom post type attachments?
- Can anyone clarify difference between archive-{posttype}.php, type-{posttype} and date.php?
- widget_posts_args not using the number of posts in widget
- gutenberg message
- Get current user id
- Print all the tags from a custom post type
- Add data to post edit page, when post is published
- How can deregister scripts for a certain custom post type?
- Custom posts – tag pagination
- Getting custom post types to properly display alphabetically
- does wp_insert_term link the term to a certain post ID?
- Custom Post Type Specific Post Template
- Custom post type category permalinks and archive pages
- One post auto attached to many another items
- Submit Custom Postypes from frontend
- Display custom post types by category
- How to display posts from a certain category in a bootstrap 5 carousel loop with multiple items?
- background featured image display using shortcode
- Define multiple prefixes for custom post type
- How to get custom post type with dynamic ID
- Query custom post type and custom field by URL parameters
- How to show posts of the same category on a page?
- Can I manage current & past editions of an annual event with a single WordPress install?
- Update 2 wordpress tables at once
- Problem displaying posts for a category in a custom taxonomy
- WordPress Front-End user restricted taxonomies
- Querying, storing, and using data from 2 separate custom post types
- How to display data with pagaination on backend?
- Edit post meta direct from post.php?
- Custom Post ‘Post Per Page’ Crashing Page?
- Load different template for CPT (in loop) in my plugin?
- getting issue with custom advance fields plugin
- Cross post type parent page added parent page to permalink but give 404
- Change the text on the Publish button
- permalink structure for single-{post-type}.php in wordpress
- Loop through multiple custom taxonomy terms and display posts for a custom post type
- show the most recent date of all posts to display on front end
- How to add custom permalink struct with DYNAMIC author to a Custom Post Type
- WPNavi pagination links not working on custom pages
- Rewrite Rule for custom post type link with or without taxonomy terms
- How to add to taxonomies to a post type
- Custom plugin contact form connecting to mailchimp API
- Posts structure named to blog, how to add month and year
- How to change post cpt with submit button?
- Filtering custom post types using category taxonomy
- Storing every individual update to the posts being updated over time?
- Rewrite nested urls for custom post type
- Custom Post Type featured option
- Change post structure
- WP Query + custom fields: How to query event posts from the current date backwards 6 months and organize it month by month?
- Custom post type Premalinks main page and details page
- Two custom post type relations
- Update Custom Field daily within 7days
- set_post_thumbnail or media_sideload_image adds image multiple times in media library
- How to use wp_set_object_terms depending on page ID?
- Change CPT Edit Target Link for Admin List
- How can I produce multiple webpages with a different output based on one entry/Page/custom Page?
- custom taxonomy not return in the code
- Rewrite rule taxonomy url with different values in one function
- How to display posts from IMPress for IDX Broker on home page? [closed]
- Permalinks for Custom Post Types and Taxonomies
- Group search results by post type, but having a unique heading for each section?
- selecting custom post types and taxonomies for hub page listing blocks
- Remote database access on another wordpress site’s custom post type
- How do I get parameters from the URL?