Make WordPress Core

Opened 12 months ago

Last modified 12 months ago

#58216 new defect (bug)

numeric tags are tagged with tag-ID instead of tag-slug in the post_class()

Reported by: ratterobert's profile ratterobert Owned by:
Milestone: Awaiting Review Priority: normal
Severity: major Version: 6.2
Component: Taxonomy Keywords: has-patch
Focuses: javascript, css, template Cc:

Description

I have created a numeric tag (title and slug are 2024). In the classes created by post_class() , the tag is output with the tag_ID .

However, I need the slug at this point, as I then filter via JavaScript.

Attachments (1)

Bildschirmfoto 2023-04-27 um 15.04.37.png (24.7 KB) - added by ratterobert 12 months ago.
tag-13 has the name and slug '2024' in wp-admin

Download all attachments as: .zip

Change History (5)

@ratterobert
12 months ago

tag-13 has the name and slug '2024' in wp-admin

#1 @SergeyBiryukov
12 months ago

  • Component changed from General to Taxonomy

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


12 months ago
#2

  • Keywords has-patch added; needs-patch removed

#3 @dilipbheda
12 months ago

@ratterobert Thank you for the report, I've fixed it with the attached PR https://github.com/WordPress/wordpress-develop/pull/4401
Please review and let me know if need any changes.

cc @SergeyBiryukov
Thanks

#4 @ratterobert
12 months ago

I think it's not line 769, but the foreach loop starting at line 569 in the get_post_class function. I changed the function like this and it works for me:

<?php
foreach ( (array) $taxonomies as $taxonomy ) {
        if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) {
                foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) {
                        if ( empty( $term->slug ) ) {
                                continue;
                        }
                        $term_class = sanitize_html_class( $term->slug );
                                // 'post_tag' uses the 'tag' prefix for backward compatibility.
                        if ( 'post_tag' === $taxonomy ) {
                                $classes[] = 'tag-' . $term_class;
                        } else {
                                $classes[] = sanitize_html_class( $taxonomy . '-' . $term_class );
                        }
                }
        }
}
Note: See TracTickets for help on using tickets.