Wordpress - check if current page has given tag ID

独自空忆成欢 提交于 2019-12-12 02:16:27

问题


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&ta‌g_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['ta‌g_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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!