从帖子ID获取Wordpress类别ID

时间:2012-06-09 07:52:19

标签: wordpress

我正在使用自定义帖子类型和自定义类别。我需要在页面中获取自定义帖子类型的类别ID。我尝试使用各种方法,但我无法获得类别ID。

<?php 
    $args = array(
                'posts_per_page'=> -1,
                 'post_type' => 'professional',
                 'orderby'=> 'id',
                 'order'=> 'asc',
                );
            query_posts($args);

    $my_posts = new WP_Query($args);
         while ($my_posts->have_posts()) : $my_posts->the_post(); // loop for posts
    function getCurrentCatID(){
    global $wp_query;
    global $post;
    $cats = get_queried_object()->term_id;
    $cat_ID = $cats[0]->cat_ID;
    return $cat_ID;
    } 
?>
<li>
    <div class="caption">
        <h3><a href="<?php  the_permalink(); ?>"><?php the_title();  ?></a></h3>
        <span class="industry"><?php getCurrentCatID($cat_ID); ?></span>
    </div>
</li>

我无法在自定义帖子类型中获取猫ID。

1 个答案:

答案 0 :(得分:1)

试试这个。

$cat_l=get_the_term_list( $post->ID, 'custom_categories', '',  '&nbsp;,&nbsp;', '' );
echo $cat_l;
相关问题