【问题标题】:Get slug of tags woocommerce product获取标签 woocommerce 产品
【发布时间】:2017-08-15 08:41:54
【问题描述】:

我尝试获取我的产品标签的名称。像这样

   $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;

我获得了我的标签列表,但我想要这个标签的 slug。

有什么想法吗?

【问题讨论】:

    标签: php wordpress woocommerce product


    【解决方案1】:
    $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;
    

    基于:Woocommerce Get product tags in array

    【讨论】:

      猜你喜欢
      • 2015-10-07
      • 1970-01-01
      • 2018-07-18
      • 2016-12-26
      • 2015-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-28
      相关资源
      最近更新 更多