Make WordPress Core

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

  1. Activate Twenty Fourteen.
  2. Appearance > Customize > Featured Content: set the tag name to featured and enable "Don't display tag on front end".
  3. Create a post with the tags featured and another tag, then publish.
  4. 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

Featured_Content::hide_the_featured_term() (filter on get_the_terms) removes the featured tag with unset( $terms[ $term->term_id ] ), but the array returned by get_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 method hide_featured_term().

Testing Instructions

  1. Activate Twenty Fourteen.
  2. Appearance > Customize > Featured Content: set the tag name to featured and enable "Don't display tag on front end".
  3. Create a post with the featured tag (plus another tag) and publish.
  4. View the post on the front end.
    • Before: the featured tag appears in the post's tag list.
    • After: the featured tag is hidden; other tags are still shown.
  5. Disable "Don't display tag on front end" and reload: the featured tag 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.

Note: See TracTickets for help on using tickets.