问题
I am using WordPress custom taxonomies.
How to check if the current page has tag_ID = "XXX"
?
If that is any help the URL on the admin page looks like this:
http://localhost/website/wp-admin/edit-tags.php?action=edit&taxonomy=company&tag_ID=13&post_type=news
The code currently used, but not working:
if (has_post_thumbnail()) {
the_post_thumbnail();
} else {
if (is_object_in_term($post - > ID, 'post_tag', '13')) {
// ID 13
}
if (is_object_in_term($post - > ID, 'post_tag', '12')) {
// ID 12
}
if (is_object_in_term($post - > ID, 'post_tag', '14')) {
// ID 14
}
}
回答1:
May be this could be useful (for given url in admin)
global $pagenow;
if ($pagenow == 'edit-tags' && $_GET['tag_ID'] == '123') // 123 is for example
{
//
}
Update: for the front end
$tag_id=get_query_var('tag_id');
if($tag_id && $tag_id=='123') // 123 is for example
{
// code
}
来源:https://stackoverflow.com/questions/11357556/wordpress-check-if-current-page-has-given-tag-id