Check if current page has given tag ID

All the tags is inside the query, it is possible to check for this via get_query_var(); all objects inside the query.
For the tag ID ask with this code: get_query_var( 'tag_ID' ); Also it is possible to check for tags, like get_query_var( 'term' ) and the taxonomy get_query_var( 'taxonomy' )

So you can create an Loop with your tag data form your taxonomy; like

$wpq = array ( 
    'post_type' => 'post',
    'post_status' => 'published',
    'taxonomy'=> get_query_var( 'taxonomy' ),
    'term'=> get_query_var( 'term' )
);
$query = new WP_Query( $wpq );
while ( $query->have_posts() ) : $query->the_post();

So you can check:
if ( 'your_tad_id=== get_query_var( ‘tag_ID’ ) ) `

  • An hint; if you will use the check via $_REQUEST-var; please filter this data or use only for if statements.

Leave a Comment

tech