Make WordPress Core

Opened 12 years ago

Closed 9 years ago

#21881 closed defect (bug) (fixed)

wp_list_categories show_option_all does not work for custom taxonomy

Reported by: arkinex's profile arkinex Owned by: boonebgorges's profile boonebgorges
Milestone: 4.3 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords:
Focuses: Cc:

Description

I am using wp_list_categories on a custom post type page to list the taxonomy values (categories). However if I include an All link it links by default to /blog/ and not /taxonomy/.

Attachments (5)

21881.patch (1021 bytes) - added by stevegrunwell 9 years ago.
21881.2.patch (1.0 KB) - added by stevegrunwell 9 years ago.
As get_query_var() can return arrays, only use get_post_type_archive_link() will receive a string
21881.3.patch (1.5 KB) - added by stevegrunwell 9 years ago.
Talking it through with Nacin, we realized that changing the "all" link based on context was the wrong behavior. Instead, if a post type is only used for one, non-built-in taxonomy, link to the archive for that post type (if it exists).
21881.4.patch (2.3 KB) - added by hrishiv90 9 years ago.
Updated patch as suggested by @boonebgorges
21881.5.patch (2.8 KB) - added by boonebgorges 9 years ago.

Download all attachments as: .zip

Change History (21)

#1 @sirzooro
12 years ago

#21881 was marked as a duplicate.

#2 @sirzooro
12 years ago

#21882 was marked as a duplicate.

#3 @SergeyBiryukov
12 years ago

  • Component changed from General to Taxonomy

#5 @wonderboymusic
10 years ago

  • Keywords needs-patch needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release

A patch will move this along. Thanks for the report, arkinex.

#6 @boonebgorges
9 years ago

  • Keywords good-first-bug added

#7 @landakram
9 years ago

arkinex, thanks for the bug report :)

It looks like there's no general category page (i.e. /category by default) that would display all posts by all categories.

Since $posts_page is the right path for displaying all posts, isn't linking to the posts page the desired behavior here?

@stevegrunwell
9 years ago

#8 @stevegrunwell
9 years ago

  • Keywords needs-testing added; needs-patch removed

Patch added, but it could use some unit tests (along with the rest of wp_list_categories(). If the post_type query var is populated, the returned URL will come from get_post_type_archive_link() instead of get_permalink( get_option( 'page_for_posts' ) ) or home_url( '/' ).

First patch, any and all feedback welcome :).

@stevegrunwell
9 years ago

As get_query_var() can return arrays, only use get_post_type_archive_link() will receive a string

This ticket was mentioned in Slack in #core by stevegrunwell. View the logs.


9 years ago

@stevegrunwell
9 years ago

Talking it through with Nacin, we realized that changing the "all" link based on context was the wrong behavior. Instead, if a post type is only used for one, non-built-in taxonomy, link to the archive for that post type (if it exists).

This ticket was mentioned in Slack in #core by stevegrunwell. View the logs.


9 years ago

#11 @boonebgorges
9 years ago

In 31301:

Add unit tests for 'show_option_all' behavior of wp_list_categories().

See #21881.

#12 @boonebgorges
9 years ago

  • Keywords needs-patch added

stevegrunwell - Thanks for working on this. The approach in the patch looks mostly good to me. The only change I'll suggest is that when a taxonomy is associated with more than one post type, we should still try to do something intelligent with it, even if it's just grabbing the first member of object_type that has_archive.

I wrote a few unit tests for the existing behavior in [31301]. Perhaps you could use them as a template for additional tests that describe the current bug. Off the top of my head, the cases seem like this: (a) more than one object_type and the first one has_archive; (b) more than one object_type and the first one does *not* has_archive; (c) none of the object_types has_archive.

@hrishiv90
9 years ago

Updated patch as suggested by @boonebgorges

#13 @hrishiv90
9 years ago

  • Keywords needs-patch removed

Hi,

As per @boonebgorges suggestion, I have updated the patch to handle all types of conditions as to check if more than one object_type and first one either has_archive enabled or disabled with continuing the check on further object types (post_type).

I used array_shift instead of normal indexing ($object_type[$i]) in the loop as the array obtained from taxonomy->object_type may start from any number as index instead of fixed number 0 depending on the post_types taxonomy has been registered with.

#14 @boonebgorges
9 years ago

  • Keywords 4.3-early added; needs-unit-tests good-first-bug removed

hrishiv90 - Thanks for the patch. This is getting close. 21881.5.patch includes a unit test for the new behavior, and simplifies the logic of 4.patch a little (also accounting for the possibility that an object_type might not be a valid post type).

#15 @boonebgorges
9 years ago

  • Keywords needs-testing 4.3-early removed
  • Milestone changed from Future Release to 4.3

#16 @boonebgorges
9 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 32292:

In wp_list_categories(), 'All' link should point to post type archive if taxonomy is not registered for 'post' or 'page'.

Instead, we point to the post type archive of the first registered
object_type that supports archives.

Props stevegrunwell, hrishiv90, boonebgorges.
Fixes #21881.

Note: See TracTickets for help on using tickets.