WordPressでtagの一覧を取得する方法

$terms = get_tags();

これでtagの一覧が取得できる。
ところが、tag登録していても利用されていないtagはこの一覧に出てこない。

WP_Term_Query::__construct() | Method | WordPress Developer Resources

$this->query_var_defaults = array(
        'taxonomy'               => null,
        'object_ids'             => null,
        'orderby'                => 'name',
        'order'                  => 'ASC',
        'hide_empty'             => true,
        'include'                => array(),
        'exclude'                => array(),
        'exclude_tree'           => array(),
        'number'                 => '',
        'offset'                 => '',
        'fields'                 => 'all',
        'count'                  => false,
        'name'                   => '',
        'slug'                   => '',
        'term_taxonomy_id'       => '',
        'hierarchical'           => true,
        'search'                 => '',
        'name__like'             => '',
        'description__like'      => '',
        'pad_counts'             => false,
        'get'                    => '',
        'child_of'               => 0,
        'parent'                 => '',
        'childless'              => false,
        'cache_domain'           => 'core',
        'update_term_meta_cache' => true,
        'meta_query'             => '',
        'meta_key'               => '',
        'meta_value'             => '',
        'meta_type'              => '',
        'meta_compare'           => '',
    );

‘hide_empty’ => true の指定をfalseに変更すればいい。

$args = array(
  'hide_empty' => false
);
$terms = get_tags($args);

コメント

コメントを残す