[wp-trac] [WordPress Trac] #58216: numeric tags are tagged with tag-ID instead of tag-slug in the post_class()

WordPress Trac noreply at wordpress.org
Tue May 2 07:58:35 UTC 2023


#58216: numeric tags are tagged with tag-ID instead of tag-slug in the post_class()
--------------------------+----------------------------------------
 Reporter:  ratterobert   |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Taxonomy      |     Version:  6.2
 Severity:  major         |  Resolution:
 Keywords:  has-patch     |     Focuses:  javascript, css, template
--------------------------+----------------------------------------

Comment (by ratterobert):

 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
 <?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 );
                         }
                 }
         }
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58216#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list