Yes!
On the admin menu hook, grab all the post types using get_post_types
, then for each type, do a query for posts of that type, and call add_submenu_page
with their edit URLs to put them in the menu.
Here's a more comprehensive alternative to IT Goldmans answer with the following additions:
- fixes a performance and caching issue that stopped it working with caching plugins and plugin filters
- works for all post types
- adds a separator and puts them at the end
- edit icons!
- handles posts with no title
- respects the posts_per_page setting and default ordering
- doesn't break custom edit links
![enter image description here](https://i.stack.imgur.com/17xfA.png)
To use, copy paste to a new PHP file in the plugins folder:
<?php
/**
* Plugin Name: Basic admin post submenus
* Plugin Author: Tom J Nowell
*/
// https://wordpress.stackexchange.com/questions/406113/is-there-a-way-to-add-the-list-of-recent-posts-into-the-admin-sub-menu-on-hover
add_action(
'admin_menu',
function () : void {
$types = get_post_types( [
'public' => true,
] );
foreach( $types as $type ) {
$parent_url = add_query_arg(
[
'post_type' => $type === 'post' ? null : $type
],
'edit.php'
);
$args = [
'post_type' => $type,
'post_status' => 'publish',
'suppress_filters' => false,
];
$posts = get_posts( $args );
if ( empty( $posts ) ) {
continue;
}
add_submenu_page(
$parent_url,
'wp-menu-separator',
'',
'read',
'',
'',
11
);
foreach ( $posts as $post ) {
$title = ! empty( $post->post_title ) ? $post->post_title : '<em>' . __( 'Untitled' ) . '</em>'
add_submenu_page(
$parent_url,
$post->post_name,
$title . '<span class="dashicons dashicons-edit"></span> ',
'read',
get_edit_post_link( $post->ID ),
'',
11
);
}
}
}
);