Reputation: 749
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?
Upvotes: 1
Views: 1203
Reputation: 253784
$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
Upvotes: 1