Make WordPress Core

Opened 6 years ago

Last modified 2 years ago

#35990 new feature request

Registering a custom post type should create a Recent CPT posts widget type

Reported by: ericlewis Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Widgets Keywords: 2nd-opinion needs-patch
Focuses: Cc:


e.g. If I register a custom post type like Reviews, it'd be nice if a widget type was created for me like "Recent Reviews".

Attachments (1)

35990.0.diff (2.3 KB) - added by westonruter 6 years ago.

Download all attachments as: .zip

Change History (10)

#1 @DrewAPicture
6 years ago

  • Keywords needs-patch added

I like this idea.

After the discussion on #21165 about making the categories widget work for other taxonomies, updating the Recent Posts widget to work with other post types would probably be the way to go, rather than creating new widgets for individual types.

I feel like a new widget for every post type could quickly get out of hand, especially if you have a few post types.

6 years ago

#2 @GaryJ
6 years ago

I agree with Drew - having a new widget for each post type is overkill. My current client site has 11 CPTs and the majority of them wouldn't be suitable for a Recent widget. If this approach is followed, rather than updating the existing widget, then it should at least be only triggered from a widget flag of some sort, to make it opt-in.

#3 @westonruter
6 years ago

Note to do this sanely, we'd need to implement #28216.

With that committed, we'd be able to introduce a new property like WP_Widget_Recent_Posts::$post_type which can then be used to determine the widget's name, description, and id_base, and more importantly to determine the post_type used in the WP_Query in the WP_Widget_Recent_Posts::widget() method.

See 35990.0.diff.

#4 @SergeyBiryukov
6 years ago

__( 'Your site’s most recent %s.', $post_type_obj->labels->name ) is not translatable, see comment:ticket:17609:3 and comment:ticket:19099:1. We'll need a new label in get_post_type_labels().

#5 @westonruter
6 years ago

In 37329:

Widgets: Allow WP_Widget subclass instances (objects) to be registered/unregistered in addition to WP_Widget subclass names (strings).

Allows widgets to be registered which rely on dependency injection. Also will allow for new widget types to be created dynamically (e.g. a Recent Posts widget for each registered post type).

See #35990.
Props mdwheele, PeterRKnight, westonruter.
Fixes #28216.

#6 @westonruter
6 years ago

With [37329], the approach in 35990.0.diff should now be viable.

#7 @netweb
6 years ago

bbPress includes its own "Recent widgets", I don't think bbPress' custom post types should be re-regisered with new "Recent widgets", they'd be duplicates and confusing for bbPress users.

This should be opt-in via a new argument in register_post_type()

#8 @keraweb
5 years ago

I agree with @netweb .
Adding this to the register_post_type arguments would be very neat and more flexible for the users/dev's.

#9 @greenshady
5 years ago

I'm not sure I see the need for a bunch of different widgets when a single widget is reusable.

Why not simply put in a drop-down <select> of available post types in the main widget class? Then, add a either a filter hook for post types to opt-in or an argument for register_post_type()?

Note: See TracTickets for help on using tickets.