Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从帖子ID获取Wordpress类别ID_Wordpress - Fatal编程技术网

从帖子ID获取Wordpress类别ID

从帖子ID获取Wordpress类别ID,wordpress,Wordpress,我使用的是自定义帖子类型和自定义类别。我需要在页面中获取自定义帖子类型的类别ID。我尝试使用各种方法,但无法获取类别ID <?php $args = array( 'posts_per_page'=> -1, 'post_type' => 'professional', 'orderby'=> 'id', 'order'=>

我使用的是自定义帖子类型和自定义类别。我需要在页面中获取自定义帖子类型的类别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>

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

    试试这个

    $cat_l=get_the_term_list( $post->ID, 'custom_categories', '',  '&nbsp;,&nbsp;', '' );
    echo $cat_l;
    
    试试这个

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