See if either of these two help you.
To use this plugin, create a new folder in your WordPress installation’s wp-content/plugins
directory and name it something like custom-post-type-listing
. Then, create a new PHP file named custom-post-type-listing.php
inside that folder and copy the code above into it.
After activating the plugin through the WordPress admin panel, you’ll see a new menu item named “Custom Post Types” under the “Dashboard” menu.
Don’t install at the same time.
<?php
/*
Plugin Name: Custom Post Type Listing
Plugin URI: https://www.example.com/
Description: A plugin to list all custom post types and their posts.
Version: 1.0
Author: Your Name
Author URI: https://www.example.com/
License: GPL2
*/
// Hook into the admin menu to add a custom page for displaying custom post types
add_action( 'admin_menu', 'cpt_listing_add_menu' );
function cpt_listing_add_menu() {
add_menu_page(
'Custom Post Types',
'Custom Post Types',
'manage_options',
'cpt-listing',
'cpt_listing_page',
'dashicons-admin-post',
25
);
}
// The callback function for rendering the custom post type listing page
function cpt_listing_page() {
$post_types = get_post_types( array( 'public' => true ), 'objects' );
// Output the custom post types and their posts
echo '<div class="wrap">';
echo '<h1>Custom Post Types and Posts</h1>';
foreach ( $post_types as $post_type ) {
echo '<h2>' . esc_html( $post_type->label ) . '</h2>';
$args = array(
'post_type' => $post_type->name,
'posts_per_page' => -1,
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
echo '<ul>';
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title() . ' | ' . esc_html( $post_type->name ) . '</li>';
}
echo '</ul>';
} else {
echo '<p>No posts found.</p>';
}
wp_reset_postdata();
}
echo '</div>';
}
<?php
/*
Plugin Name: Custom Post Type Listing
Plugin URI: https://www.example.com/
Description: A plugin to list all custom post types and their posts.
Version: 1.0
Author: Your Name
Author URI: https://www.example.com/
License: GPL2
*/
// Hook into the admin menu to add a custom page for displaying custom post types
add_action( 'admin_menu', 'cpt_listing_add_menu' );
function cpt_listing_add_menu() {
add_menu_page(
'Custom Post Types',
'Custom Post Types',
'manage_options',
'cpt-listing',
'cpt_listing_page',
'dashicons-admin-post',
25
);
}
// The callback function for rendering the custom post type listing page
function cpt_listing_page() {
$post_types = get_post_types( array( 'public' => true ), 'objects' );
// Output the custom post types and their posts
echo '<div class="wrap">';
echo '<h1>Custom Post Types and Posts</h1>';
foreach ( $post_types as $post_type ) {
echo '<h2>' . esc_html( $post_type->label ) . '</h2>';
$post_type_url = 'edit.php?post_type=' . $post_type->name;
echo '<a href="' . esc_url( $post_type_url ) . '">View All ' . esc_html( $post_type->label ) . '</a><br>';
}
echo '</div>';
}