我尝试获得产品标签的名字。像这样
$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;
我获得了我的标签列表,但是我想要这些标签。
任何的想法?
$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;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句