简体   繁体   中英

Get slug of tags woocommerce product

I try to get a slug name of the tags of my product. Like this

   $args = array( 'post_type' => 'product');
$list_tags = [];
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
  $tag = get_the_term_list($post->ID, 'product_tag', '', ',' ); 
  array_push($list_tags, $tag );
endwhile;
return $list_tags;

I obtain a list of my tags but I want the slug of this tags.

Any idea?

$args = array( 'post_type' => 'product');
$list_tags = array()
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
    $terms = get_the_terms( $post->ID, 'product_tag' );;
    if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
        foreach ( $terms as $term ) {
            $list_tags = $term->slug;
            array_push($list_tags, $terms );
        }
    }
endwhile;
return $list_tags;

Based on: Woocommerce Get product tags in array

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM