I am using custom taxonomies.
How to check if current page has tag_ID = "XXX"
?
If that is any help the URL form WordPress admin looks like this:
http://localhost/website/wp-admin/edit-tags.php?action=edit&taxonomy=company&taâg_ID=13&post_type=news
Update. Here is code which I’m currently using. Does not work.
<?php
function insert_news($company = 0)
{
global $post;
$count = 0;
$news_query = new WP_Query(array(
'post_type' => 'news',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'ASC',
'company' => $company
));
$total_count = $news_query->post_count;
while ($news_query->have_posts()):
$news_query->the_post();
$count++;
$tag_id = get_query_var('tag_id');
if ($tag_id && $tag_id == '14') {
// ID 14
} else if ($tag_id && $tag_id == '13') {
// ID 13
} else if ($tag_id && $tag_id == '12') {
// ID 12
}
endwhile;
}
?>
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, likeget_query_var( 'term' )
and the taxonomyget_query_var( 'taxonomy' )
So you can create an Loop with your tag data form your taxonomy; like
So you can check:
if ( 'your_tad_id
=== get_query_var( ‘tag_ID’ ) ) `$_REQUEST
-var; please filter this data or use only for if statements.Update: Regarding the following comment:
So I’m guessing you mean “check if editing tag with ID X”?
You really must be a little clearer with your teminology 😉
If you’re only interested in 3 subsequent tag_id’s you could start with narrowing down your query, using $_POST[‘tag_id’] and ‘tag__in’:
And you can refer back to the $query_tag_id variable in the if conditional tests, like:
I’d expect that the suggestion made by TheDeadMedic would do the trick when you combine it with the above. Like this for the middle if test:
Failing that you could always get all the tag ids for the active post in the while loop and use those in the if tests. So you’d have to replace
with:
If you’re certain your posts are only going to have one tag, you could simplify things by using:
Update:
On a side note, get_query_var() does not work because it looks for the parameters you set in the query. You didn’t set any tag_id in the query, so it does not return anything. So changing the query as I suggested at the start of my answer would get you a return value, but not one you could use.
For WordPress’ sake, throw that into a function in the functions.php and add a hook, like init (Bare in mind this would be specific just to that tag)
You could make it conditional by setting a couple variables and testing to see if it equals a particular value.
Try globalizing $wp_query since your doing this within a function.
Haven’t tested this, but it should work.