categories – get_the_category:An error occurred when I tried to getthe ID of the category

Question

An error occurred when I tried to get the ID of the category.The obtained id is the id of its subcategory.Below is the code:

else if (is_category()){
    $title = single_cat_title( '', false ).$weiba;
    $description = htmlentities(strip_tags(trim(category_description())), ENT_QUOTES, 'UTF-8');
    $category_info = get_the_category();
    $category_id = $category_info[0]->cat_ID;
    $keywords = get_option('_category_keywords'.$category_id);
    $keywords = $keywords.$category_id;
  }

I printed the obtained array as follows:

Array
(
    [0] => WP_Term Object
        (
            [term_id] => 3
            [name] => 行业资讯
            [slug] => hynews
            [term_group] => 0
            [term_taxonomy_id] => 3
            [taxonomy] => category
            [description] => 关于厂房夹心板,畜牧用夹心板,净化板,冷库板夹心板的最新资讯。
            [parent] => 1
            [count] => 47
            [filter] => raw
            [cat_ID] => 3
            [category_count] => 47
            [category_description] => 关于厂房夹心板,畜牧用夹心板,净化板,冷库板夹心板的最新资讯。
            [cat_name] => 行业资讯
            [category_nicename] => hynews
            [category_parent] => 1
        )

 

Can anyone tell me how to solve it, thanks a lot!//有没有大佬可以告诉我怎么解决的,非常感谢!

0
eddie 3 weeks 2022-11-11T00:11:59-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse