Support » Plugins » programming – how to get the tag id from the viewed tag page

  • hello,

    iam trying to write a little plugin for my tag-archive, but i got some problems getting some informations in the programming:

    My plugin has to check, if the viewed site is a tag-archive and if so, i need to get the “tag_id” from the viewed archives tag.

    How can i get this information?

    I found the functions:

    get_query_var('tag');
    get_query_var('tag_slug__and');

    to get the tag_id/id`s, but when i use them in my plugin i receive nothing:

    global $wp_query;
    echo get_query_var('tag_id');

    The function is_tag() isnt working for plugins also.
    How can i find out what the tag_id is?

    Can anyone help me please 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • is_tag() and get_query_var(‘tag’) work just fine. is_tag() will return true on a tag archive page (like http://example.com/?tag=whatever or http://example.com/tag/whatever/ ). get_query_var(‘tag’) in those cases would return “whatever”.

    But remember, plugins load *before* the query is parsed and created. So you have to defer using that stuff until at least the init action hook.

    hi otto42,

    plugins load before the query is parsed and created?
    Thats sounds like my problem!

    have to defer using that stuff until at least the init action hook.

    Im a quite unskilled in programming plugins. How can i realize that?

    Thanks 4 your help!

    Well, it largely depends on what you want your plugin to do… I mean, plugins load before most things, and so they can’t make any real output on their own. They use action hooks to change the output elsewhere.

    In other words, I need more information, your question is too broad. What, exactly, are you trying to do? Be specific.

    Anyway, I suggest you read up on the Plugin API. If you don’t know actions and filters, you can’t write a plugin.

    http://codex.wordpress.org/Plugin_API

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘programming – how to get the tag id from the viewed tag page’ is closed to new replies.