wordpress后台怎么导出所有的tags标签词

2025-03-04 18:23:37
推荐回答(1个)
回答1:

建议你这样试试看:

/*
Prior to 4.5.0, the first parameter of `get_terms()` was a taxonomy or list of taxonomies:

$terms = get_terms( 'post_tag', array(
'hide_empty' => false,
) );

Since 4.5.0, taxonomies should be passed via the 'taxonomy' argument in the `$args` array:
*/
$terms = get_terms( array(
'taxonomy' => 'post_tag',
'hide_empty' => false,
) );
/*
print_r($terms);
Array
(
    [0] => WP_Term Object
        (
            [term_id] => 2
            [name] => 测试标签
            [slug] => tags1
            [term_group] => 0
            [term_taxonomy_id] => 2
            [taxonomy] => post_tag
            [description] => 
            [parent] => 0
            [count] => 0
            [filter] => raw
        )

)
*/

$tags = array();
if ( $terms ) {
  foreach ( $terms as $key => $term ) {
    $tags[] = $term->name;
  }
}
print_r($tags);
/*
Array
(
    [0] => 测试标签
)
*/