0

I already know how to custom the default Recent Activity widget displayed in Dashboard in order to show the last Custom Post Types published :

add_filter( 'dashboard_recent_posts_query_args', function(array $queryArgs) {
    $postTypes = get_post_types([
        'public'          => true,
        'capability_type' => 'post',
    ]);

    if ( is_array( $postTypes ) ) {
        $queryArgs['post_type'] = $postTypes;
    }

    return $queryArgs;
}, 15 );

So, now, the widget is displaying the last post and last custom post published. But what about the pages ?

How to add the pages to this widget ?

1 Answer 1

0

Add page post type to your code (tested):

add_filter( 'dashboard_recent_posts_query_args', function(array $queryArgs) {
    $postTypes = get_post_types([
        'public'          => true,
        'capability_type' => 'post',
    ]);

   $postTypes[] = 'page';

    if ( is_array( $postTypes ) ) {
        $queryArgs['post_type'] = $postTypes;
    }

    return $queryArgs;
}, 15 );

The reason your original code did not include pages is because pages have their own separate capability type: edit_page instead of edit_post.

2
  • Thanks a lot ! I have been trying different solutions all day long ! May I ask where you found that pages had the edit_page capability type ?
    – PhpDoe
    Jun 6, 2023 at 9:21
  • 1
    It’s hard to say, as I’ve known for a long time. The documentation for the function that creates the built-in post types shows that page is registered with a different capability type: developer.wordpress.org/reference/functions/….
    – Caleb
    Jun 6, 2023 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.