You don’t need to make a new WP_Query
to display the posts in the requested tag (beaches
in question), because when the page is requested, WordPress will parse the query args from the URL (or the rewrite rule that matches the URL path) and automatically make a WP_Query
call which fetches the tag’s posts from the database. And that query is called the “main query” which runs automatically on page load, before the template like tag.php
or single.php
is determined.
So in your tag template, you just need to display the (main) loop, or the posts for the main query, i.e. while ( have_posts() ) { the_post(); /* your code here; e.g. call the_title() */ }
.
However, if you wanted to know how to retrieve the current tag object (which is an instance of WP_Term
), then use get_queried_object()
. Or get_queried_object_id()
to retrieve just the tag ID.
Or have I misread your question?