Skip to content

Instantly share code, notes, and snippets.

@Mte90
Created September 18, 2015 11:27
Show Gist options
  • Save Mte90/708e54b21b1f7372b48a to your computer and use it in GitHub Desktop.
Save Mte90/708e54b21b1f7372b48a to your computer and use it in GitHub Desktop.
Add your cpts to the Widget Activity of the Dashboard in WordPress
<?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;
}
}
@AkremBelkahla
Copy link

@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 !

@douglasanro
Copy link

@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.

@AkremBelkahla
Copy link

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