Using WordPress ‘dashboard_recent_drafts_query_args’ PHP filter

The dashboard_recent_drafts_query_args WordPress PHP filter allows you to modify the query arguments for the ‘Recent Drafts’ dashboard widget.

Usage

add_filter('dashboard_recent_drafts_query_args', 'your_custom_function_name');
function your_custom_function_name($query_args) {
    // your custom code here
    return $query_args;
}

Parameters

  • $query_args (array): The query arguments for the ‘Recent Drafts’ dashboard widget.

More information

See WordPress Developer Resources: dashboard_recent_drafts_query_args

Examples

Change number of displayed drafts

To change the number of displayed drafts in the ‘Recent Drafts’ dashboard widget, modify the ‘posts_per_page’ parameter.

add_filter('dashboard_recent_drafts_query_args', 'change_recent_drafts_count');
function change_recent_drafts_count($query_args) {
    $query_args['posts_per_page'] = 10; // Show 10 recent drafts
    return $query_args;
}

Order drafts by title

To order the drafts in the ‘Recent Drafts’ dashboard widget by title, modify the ‘orderby’ and ‘order’ parameters.

add_filter('dashboard_recent_drafts_query_args', 'order_drafts_by_title');
function order_drafts_by_title($query_args) {
    $query_args['orderby'] = 'title';
    $query_args['order'] = 'ASC'; // Sort drafts alphabetically
    return $query_args;
}

Show drafts from a specific category

To show drafts from a specific category in the ‘Recent Drafts’ dashboard widget, modify the ‘category_name’ parameter.

add_filter('dashboard_recent_drafts_query_args', 'show_drafts_from_category');
function show_drafts_from_category($query_args) {
    $query_args['category_name'] = 'news'; // Show drafts from the 'news' category
    return $query_args;
}

Exclude drafts from a specific author

To exclude drafts from a specific author in the ‘Recent Drafts’ dashboard widget, modify the ‘author__not_in’ parameter.

add_filter('dashboard_recent_drafts_query_args', 'exclude_drafts_from_author');
function exclude_drafts_from_author($query_args) {
    $query_args['author__not_in'] = array(2); // Exclude drafts from author with ID 2
    return $query_args;
}

Show drafts with a specific tag

To show drafts with a specific tag in the ‘Recent Drafts’ dashboard widget, modify the ‘tag’ parameter.

add_filter('dashboard_recent_drafts_query_args', 'show_drafts_with_tag');
function show_drafts_with_tag($query_args) {
    $query_args['tag'] = 'featured'; // Show drafts with the 'featured' tag
    return $query_args;
}