Make WordPress Core

Opened 3 years ago

Last modified 3 months ago

#35990 reopened feature request

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

Reported by: ericlewis Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Widgets Keywords: 2nd-opinion, needs-patch, bulk-reopened
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 3 years ago.

Download all attachments as: .zip

Change History (12)

#1 @DrewAPicture
3 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.

3 years ago

#2 @GaryJ
3 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
3 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
3 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
3 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
3 years ago

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

#7 @netweb
3 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
3 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
3 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()?

#10 @iseulde
5 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

This ticket has not seen any activity in over *two* years, so I'm closing it as "wontfix".

The ticket may lack decisiveness, may have become irrelevant, or may not have gathered enough interest.

If you think this ticket does deserve some attention again, feel free to reopen.

For bugs, it would be great if you could provide updated steps to reproduce against the latest version of WordPress (5.0.2 at the time of writing). Remember images or a video can be superior to explain a problem. At the very least, quickly test again to make sure the bug still exists.

If it’s an enhancement or feature, some extra motivation may help.

Thank you for your contributions to WordPress! <3

#11 @JeffPaul
3 months ago

  • Keywords bulk-reopened added
  • Milestone set to Awaiting Review
  • Resolution wontfix deleted
  • Status changed from closed to reopened

A decision was made to reopen tickets that were closed in the bulk edit that this ticket was affected by. This ticket is being placed back into the Awaiting Review milestone so it can be individually evaluated and verified to determine if it is still relevant/valid or reproducible.

Note: See TracTickets for help on using tickets.