Make WordPress Core

Opened 9 years ago

Closed 2 years ago

#35990 closed feature request (reported-upstream)

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

Reported by: ericlewis's profile ericlewis Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Widgets Keywords:
Focuses: Cc:

Description

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 9 years ago.

Download all attachments as: .zip

Change History (11)

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

@westonruter
9 years ago

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

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

#7 @netweb
9 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
8 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
8 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 @desrosj
2 years ago

  • Keywords 2nd-opinion needs-patch removed
  • Resolution set to reported-upstream
  • Status changed from new to closed

Now that all widgets are blocks and this widget has been ported to the Latest Posts block, I'm going to close this one out as this is now something that should be added to that block.

There is an issue upstream to continue discussion.

If someone feels strongly that this should be added to the classic widget, this can be reopened with a refreshed patch.

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()?

I think I prefer this approach, but I don't think it needs to be opt-in. As long as the default value is post then sites that added the widget before this was introduced should continue to work as they always have.

Note: See TracTickets for help on using tickets.