Opened 3 days ago
Last modified 3 days ago
#66192 new defect (bug)
Twenty Fourteen: Featured tag is not hidden in post tag lists on the front end
| Reported by: | devang100 | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Bundled Theme | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
Description
When Twenty Fourteen's Featured Content option "Don't display tag on front end" is enabled, the featured tag is still displayed in a post's tag list on the front end (e.g. the tag links under a single post).
Steps to Reproduce
- Activate Twenty Fourteen.
- Appearance > Customize > Featured Content: set the tag name to
featuredand enable "Don't display tag on front end". - Create a post with the tags
featuredand another tag, then publish. - View the post on the front end.
Expected Results
The featured tag is hidden from the post's tag list.
Actual Results
The featured tag is shown in the post's tag list.
Cause
Featured_Content::hide_the_featured_term() (filter on get_the_terms) removes the matching term with:
unset( $terms[ $term->term_id ] );
The array returned by get_the_terms() is indexed from 0, not keyed by term ID, so the featured tag stays in the list. Worse, if the post has more tags than the featured tag's ID, a different, unrelated tag is removed instead (e.g. featured tag ID 3 on a post with 4+ tags hides the 4th tag).
The sibling method hide_featured_term() (filter on get_terms) already uses the loop index correctly:
unset( $terms[ $order ] );
Proposed Fix
Use the loop index in hide_the_featured_term() as well:
unset( $terms[ $order ] );
I tested this locally (WordPress 7.2-alpha-63166-src, PHP 8.3.33): with the fix, the featured tag is hidden on the front end when the option is enabled, and still shown when the option is disabled.
Found while testing #64882 (a different issue in the same file). I'll submit a PR.
Change History (1)
This ticket was mentioned in PR #13775 on WordPress/wordpress-develop by @devang100.
3 days ago
#1
- Keywords has-patch added
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Featured_Content::hide_the_featured_term()(filter onget_the_terms) removes the featured tag withunset( $terms[ $term->term_id ] ), but the array returned byget_the_terms()is indexed from 0, not keyed by term ID. So the featured tag is still shown on the front end when "Don't display tag on front end" is enabled, and an unrelated tag can be removed instead.This PR uses the loop index (
unset( $terms[ $order ] )), matching the sibling methodhide_featured_term().Testing Instructions
featuredand enable "Don't display tag on front end".featuredtag (plus another tag) and publish.featuredtag appears in the post's tag list.featuredtag is hidden; other tags are still shown.featuredtag is shown again.Trac ticket: https://core.trac.wordpress.org/ticket/66192
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.