WordPress.org

Ready to get started?Download WordPress

Forums

programming - how to get the tag id from the viewed tag page (4 posts)

  1. Tobias
    Member
    Posted 6 years ago #

    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 :-)

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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.

  3. Tobias
    Member
    Posted 6 years ago #

    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!

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic