Make WordPress Core

Opened 3 weeks ago

Closed 3 weeks ago

Last modified 12 days ago

#62440 closed defect (bug) (fixed)

"Most Used" Category Tabs Not Synced with "All Categories" Tab in Classic Editor

Reported by: charleslf's profile charleslf Owned by: azaozz's profile azaozz
Milestone: 6.7.1 Priority: normal
Severity: normal Version: 6.7
Component: Editor Keywords: has-patch needs-testing fixed-major commit dev-reviewed
Focuses: Cc:

Description

Description

When using the Classic Editor, the "Most Used" category tabs are not properly synced with the "All Categories" tab. This issue appears to have been introduced after the fix for #61014(https://core.trac.wordpress.org/ticket/61014), as the code block in post.js does not reflect the updated ID structure.

Steps to Reproduce

# Go to the "Posts" section in the WordPress admin panel.
# Add or edit a post.
# Open the "Categories" meta box.
# Notice that when selecting categories from the "All Categories" tab, the selections do not update the "Most Used" tab, and vice versa.
# This behavior occurs when the Classic Editor is enabled.

Expected Behavior

The "Most Used" category tab should automatically sync with the "All Categories" tab, maintaining consistency between the two views.

Actual Behavior

The "Most Used" category tab is not updated when categories are selected or deselected in the "All Categories" tab.

Code Analysis

The bug appears to be related to the following block of code in post.js:

  // Sync checked items between "All {taxonomy}" and "Most used" lists.
  $('#' + taxonomy + 'checklist, #' + taxonomy + 'checklist-pop').on(
      'click',
      'li.popular-category > label input[type="checkbox"]',
      function() {
          var t = $(this), c = t.is(':checked'), id = t.val();
          if ( id && t.parents('#taxonomy-'+taxonomy).length )
              $('#in-' + taxonomy + '-' + id + ', #in-popular-' + taxonomy + '-' + id).prop( 'checked', c );
      }
  );

This block does not seem to account for the changed ID structure introduced in the fix for #61014(https://core.trac.wordpress.org/ticket/61014), causing the syncing issue between the two category tabs.

Attachments (1)

62440.mp4 (560.0 KB) - added by dhruvang21 3 weeks ago.

Download all attachments as: .zip

Change History (21)

#1 @im3dabasia1
3 weeks ago

Hi @charleslf,

Thank you for raising this ticket. I attempted to reproduce the issue but found that the "Most Used" categories section appears to be working as expected.

Here’s what I tested:

  1. I assigned a category to a post.
  2. When creating a second post, the "Most Used" categories tab displayed the category I had used previously.
  3. I added another category to the second post, and the "Most Used" tab updated accordingly based on the used categories.

I have recorded my test for reference: https://jumpshare.com/s/G6jhPLHR7F1JVLYLFkqK

Please let me know if I might have missed any specific steps or scenarios that could help in reproducing the issue. Thank you

Last edited 3 weeks ago by im3dabasia1 (previous) (diff)

#2 @charleslf
3 weeks ago

Hello @im3dabasia1,

The steps that I followed are:

  1. Enter the "Add New Post" page
  2. Select the "Most Used" tab
  3. Check any category
  4. Switch back to the "All Categories" tab. No category will be checked.
  5. If the post is published, it will be Uncategorized.

Here is a recording to better illustrate the issue: https://streamable.com/jg725h

#3 @im3dabasia1
3 weeks ago

Hello @charleslf,

Thank you for clarifying! You’re correct—I was able to reproduce the issue, and it does indeed appear to be a bug.

Additionally, while testing, I noticed another related issue:

  1. Navigate to the "Add New Post" page.
  2. Select the "Most Used" tab in the Categories section.
  3. Check any category.
  4. Save or update the post.
  5. Upon reviewing the Categories section, the category selected in step 3 does not remain checked, neither in the "Most Used" tab nor in "All Categories."

This ticket was mentioned in PR #7810 on WordPress/wordpress-develop by @im3dabasia1.


3 weeks ago
#4

  • Keywords has-patch added

Trac ticket:https://core.trac.wordpress.org/ticket/62440

### Description:
This PR addresses a bug where the "Most Used" category tab was not synced with the "All Categories" tab in the Classic Editor. When selecting categories in the "Most Used" tab, the changes were not reflected in the "All Categories" tab, causing inconsistency in category selection.

### Fix:

  • Added functionality to ensure the category selection in the "Most Used" tab correctly updates the "All Categories" tab.
  • Updated the event listeners to ensure proper syncing of checkbox states between the two tabs.
  • The issue occurred because the 'All Categories' section had a suffix appended to it, as shown in the screenshot below.

https://github.com/user-attachments/assets/1cc7d93a-0590-4ede-ab27-77d3d30d9d0f

### Steps to Test:

  1. Open the Classic Editor in WordPress.
  2. Go to the "Categories" section.
  3. Select a category from the Most used section.
  4. Notice that the category won't be checked in the "All categories" section.
  5. Their is No sync between categories checked in the "Most used" section and "All categories" section

### Video demonstration

Before:

https://github.com/user-attachments/assets/1f2975ba-12e8-47f1-b9ec-671325dbf6ea

After:

https://github.com/user-attachments/assets/0830a5a3-67e8-4131-8b1d-406adc5fcf8d

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


3 weeks ago

#6 @desrosj
3 weeks ago

  • Component changed from General to Editor
  • Milestone changed from Awaiting Review to 6.7.1

Possibly related: #62445.

Since #61014 was included in 6.7, moving this to 6.7.1 to investigate and test.

@azaozz commented on PR #7810:


3 weeks ago
#7

Hi @im3dabasia, thanks for the patch. Seems to work well here.
This is a super old JS. Pushed couple of small changes: limit it only to input elements as it was matching li too, also shortened it a bit. Please see if it still works well. This seems to also work with the previous HTML IDs so if someone is using a custom walker class, it won't break.

#8 @azaozz
3 weeks ago

  • Keywords needs-testing added

There are several reports that seem related. Changes to the selected categories not being saved when using the classic editor.

I can reproduce both types of errors and the PR seems to work well here. Thinking this will be good for 6.7.1 after a bit more testing.

#9 @azaozz
3 weeks ago

#62445 was marked as a duplicate.

@im3dabasia1 commented on PR #7810:


3 weeks ago
#10

Hi @im3dabasia, thanks for the patch. Seems to work well here. This is a super old JS. Pushed couple of small changes: limit it only to input elements as it was matching li too, also shortened it a bit. Please see if it still works well. This seems to also work with the previous HTML IDs so if someone is using a custom walker class, it won't break.

I tested it, and it works as expected. Thanks for the updates!

#11 @dhruvang21
3 weeks ago

Test Report

Description

This report validates that this patch syncs the most used categories and categories tab selection.

Patch tested: https://patch-diff.githubusercontent.com/raw/WordPress/wordpress-develop/pull/7810.diff

Environment

  • WordPress: 6.8-alpha-59274-src
  • PHP: 8.2.22
  • Server: nginx/1.27.0
  • Database: mysqli (Server: 8.0.39 / Client: mysqlnd 8.2.22)
  • Browser: Chrome 128.0.0.0
  • OS: Linux
  • Theme: Twenty Twenty-Five 1.0
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.0

Actual Results

  1. ✅ Issue resolved with patch.

Supplemental Artifacts

Added as Attachment

Last edited 3 weeks ago by dhruvang21 (previous) (diff)

@dhruvang21
3 weeks ago

#12 @azaozz
3 weeks ago

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

In 59414:

Editor: Fix the JS to select, save, and update categories on the old Edit Post screen.

Props: charleslf, im3dabasia1, desrosj, dhruvang21, Zargarov, sainathpoojary, azaozz
Fixes: #62440

#13 @desrosj
3 weeks ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening to consider backporting.

#14 @desrosj
3 weeks ago

  • Keywords commit dev-reviewed added

Thanks everyone, looks good and tests good for me. Going to backport.

#15 @desrosj
3 weeks ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 59421:

Editor: Fix the JS to select, save, and update categories on the old Edit Post screen.

Reviewed by desrosj, azaozz.
Merges [59414] to the 6.7 branch.

Props: charleslf, im3dabasia1, desrosj, dhruvang21, Zargarov, sainathpoojary, azaozz.
Fixes: #62440.

#16 follow-up: @creatis
2 weeks ago

Version 6.7.1

Multiple checkboxes can now be set instead of one selected checkbox.
In the screenshot, I clicked on Full Time. The Contract checkbox was set by itself.

There is no problem in the “Most Used” tab. The checkboxes are in the WP Job Manager plugin.

https://s3.amazonaws.com/i.snag.gy/bFk04o.jpg

https://s3.amazonaws.com/i.snag.gy/PVy7p1.jpg

#17 in reply to: ↑ 16 @powerbuoy
2 weeks ago

Having this exact same issue. It seems to happen when selecting a category with an ID that starts with the same number as other categories. For example, selecting the category #in-category-5-2 any other category that starts with 5 is also selected, for example #in-category-50-2, #in-category-51-2, #in-category-58-2 etc.

Replying to creatis:

Version 6.7.1

Multiple checkboxes can now be set instead of one selected checkbox.
In the screenshot, I clicked on Full Time. The Contract checkbox was set by itself.

There is no problem in the “Most Used” tab. The checkboxes are in the WP Job Manager plugin.

https://s3.amazonaws.com/i.snag.gy/bFk04o.jpg

https://s3.amazonaws.com/i.snag.gy/PVy7p1.jpg

#18 follow-up: @dhruvang21
13 days ago

@powerbuoy your issue might be related to https://core.trac.wordpress.org/ticket/62504

#19 in reply to: ↑ 18 @powerbuoy
13 days ago

Yea, that seems to be the same issue.

Replying to dhruvang21:

@powerbuoy your issue might be related to https://core.trac.wordpress.org/ticket/62504

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


12 days ago

Note: See TracTickets for help on using tickets.