get_cat_ID()通过分类名获取分类ID,如果没检索到数据则返回0
<?php get_cat_ID( $cat_name ) ?>
$cat_name
(string) (可选) 分类名称,默认为 ‘General’ .
默认: ‘General’
(整数)
出错时返回0,成功则返回类别编号。
以下是在The_Loop(循环)中使用该函数的基本示例。
<?php
$category_id = get_cat_id('Category Name');
$q = 'cat=' . $category_id;
query_posts($q);
if (have_posts()) : while (have_posts()) : the_post();
the_content();
endwhile; endif;
?>
get_cat_ID() 位于 wp-includes/category.php中。