# Recent Posts Widget Includes Custom Post Types

> Makes the Recent Posts widget list your custom post types, such as portfolio items, recipes or events, together with blog posts.

- Type: PHP
- Runs: Run everywhere
- Category: [Widgets](https://wpide.com/library/category/widgets/)
- Tags: widgets, recent-posts, post-types
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/recent-posts-widget-custom-post-types/

## Code

```php
// Content types listed by the Recent Posts widget and the Latest Posts block in widget areas.
// Empty = blog posts plus every public custom post type.
$wpide_recent_widget_types = array();

add_filter( 'widget_posts_args', function ( $args ) use ( $wpide_recent_widget_types ) {
    $types = $wpide_recent_widget_types;

    if ( ! $types ) {
        $types = array_merge( array( 'post' ), array_values( get_post_types( array( 'public' => true, '_builtin' => false ) ) ) );
    }

    $args['post_type'] = array_values( array_filter( $types, 'post_type_exists' ) );

    return $args;
} );
```

## Notes

Leave the list empty to include every public custom post type, or name the exact types to show.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Recent Posts Widget Includes Custom Post Types" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
