Opened 18 months ago
Last modified 17 months ago
#58216 new defect (bug)
numeric tags are tagged with tag-ID instead of tag-slug in the post_class()
Reported by: | 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)
Change History (5)
This ticket was mentioned in PR #4401 on WordPress/wordpress-develop by @dilipbheda.
17 months ago
#2
- Keywords has-patch added; needs-patch removed
Trac ticket: https://core.trac.wordpress.org/ticket/58216
#3
@
17 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
@
17 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 ); } } } }
tag-13 has the name and slug '2024' in wp-admin