Created
September 18, 2015 11:27
-
-
Save Mte90/708e54b21b1f7372b48a to your computer and use it in GitHub Desktop.
Add your cpts to the Widget Activity of the Dashboard in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Dashboard Widget Activity Custom Post Type | |
Plugin URI: | |
Description: | |
Author: Daniele Mte90 Scasciafratte | |
Version: 1.0.0 | |
Author URI: http://mte90.net | |
*/ | |
//Add the support for your cpt in the Widget Activity of the Admin Dashboard | |
if ( is_admin() ) { | |
add_filter( 'dashboard_recent_posts_query_args', 'add_page_to_dashboard_activity' ); | |
function add_page_to_dashboard_activity( $query_args ) { | |
if ( is_array( $query_args[ 'post_type' ] ) ) { | |
//Set yout post type | |
$query_args[ 'post_type' ][] = 'page'; | |
} else { | |
$temp = array( $query_args[ 'post_type' ], 'page' ); | |
$query_args[ 'post_type' ] = $temp; | |
} | |
return $query_args; | |
} | |
} |
Thanks.. it works for just one kind of custom post type...
What if I have two diferent custom post types?
@tallieven try that way:
if ( is_admin() ) {
add_filter( 'dashboard_recent_posts_query_args', 'add_page_to_dashboard_activity' );
function add_page_to_dashboard_activity( $query ) {
// Return all post types
$post_types = get_post_types();
// Return post types of your choice
// $post_types = ['post', 'foo', 'bar'];
if ( is_array( $query['post_type'] ) ) {
$query['post_type'] = $post_types;
} else {
$temp = $post_types;
$query['post_type'] = $temp;
}
return $query;
}
}
@douglasanro
Is it possible to add post type name and author next to post name ? and increase the number of last posts (more than 5) ?
Thanks !
@thegreenarrow
Well, the default dashboard_recent_posts_query_args
accepts all WP_query
arguments, like posts_per_page
to increase the number of posts see here. But, this function only return date and title.
The easy way to display other fields is creating a custom dashboard widget
, like this, and add the loop
with all fields you wish (you can use the core function loop), and implement post type and author fields.
Thank you, that's exactly what i need !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@MajorRedbeard just
$query_args['order'] = 'DESC'; $query_args['orderby'] = 'date';
. If you want to update how many posts are displayed update$query_args['posts_per_page'] = $int;
It's that easy. Thedashboard_recent_posts_query_args
hook accepts all of the same arguments as WP_Query.