Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wordpress: display current tag-id

Tags:

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?

like image 965
iMax Avatar asked Oct 25 '25 04:10

iMax


1 Answers

You can do the following

     $tag_id = get_queried_object()->term_id;

And then

    $args = array(
        'tag' => $tag_id,
    );
like image 166
MirzaP Avatar answered Oct 27 '25 01:10

MirzaP



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!