wordpress: display current tag-id

时间:2016-10-19 13:38:38

标签: wordpress tags

With

$tag = single_tag_title('', false);

I can get the name of the currently chosen tag. Right?

But how can I get also the ID of the chosen tag? "single_tag_id" does not exist. And afterwards I would like to show only posts with the tag-id.

$args = array(
            'tag' => 'ID HERE?',
        );

But I can not put a number into 'tag'. How can I filter with tag-id and not do it by name?

1 个答案:

答案 0 :(得分:4)

您可以执行以下操作

     $tag_id = get_queried_object()->term_id;

然后

    $args = array(
        'tag' => $tag_id,
    );