Opened 10 years ago
Closed 10 years ago
#29374 closed enhancement (fixed)
Add hook(s) to include other post types in the Activity widget
Reported by: | samueljmello | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 4.2 | Priority: | normal |
Severity: | normal | Version: | 3.8 |
Component: | Posts, Post Types | Keywords: | has-patch commit |
Focuses: | administration | Cc: |
Description
wp_dashboard_recent_posts does not include custom post types (or pages) and gives no filter for adding them in manually.
Ideally wp_dashboard_recent_posts should get all registered post types (as well as post and pages) when showing recent activity in the dashboard.
At the very least, make it modifiable with an action or filter. Right now the only way is to remove the activity widget and re-add your own modding the current function in a plugin.
Attachments (1)
Change History (11)
#1
@
10 years ago
- Component changed from General to Widgets
- Summary changed from wp_dashboard_recent_posts to Add hook(s) to include other post types in the Activity widget
- Type changed from defect (bug) to enhancement
#3
@
10 years ago
wp_dashboard_recent_posts does not include custom post types (or pages) and gives no filter for adding them in manually.
You can use pre_get_posts
action as a workaround:
function add_custom_post_types_to_activity_widget( $query ) { if ( ! is_admin() || 'dashboard' !== get_current_screen()->id ) { return; } // Ignore Drafts section in Quick Draft widget if ( 'draft' === $query->get( 'post_status' ) ) { return; } $query->set( 'post_type', get_post_types( array( 'public' => true ) ) ); } add_action( 'pre_get_posts', 'add_custom_post_types_to_activity_widget' );
#5
@
10 years ago
Thanks, Sergey. Elegant. pre_get_posts
is extremely powerful and can do almost anything. It's no problem making it work, but to tame it not to do it when it shouldn't.
But I hope, some day, using this method is not necessary for such a simple task. It should show all public post types by default, and perhaps have a filter to exclude some.
#6
@
10 years ago
- Keywords has-patch added
- Milestone changed from Awaiting Review to 4.2
29374.1.diff adds a filter to wp_dashboard_recent_posts()
to make the query args filterable.
"Ideally wp_dashboard_recent_posts should get all registered post types"
I do not agree, i prefer to say "only public ones" or why not add a support like "dashboard_stat".