Get category name from post id

Is it possible lớn get the category name of a category given the Post ID, the following code works lớn get the Category Id, but how can I get the name?


Bạn đang xem: Get category name from post id



here you go get_the_category( $post->ID ); will return the array of categories of that post you need to loop through the array

$category_detail=get_the_category("";//$post->IDforeach($category_detail as $cd)emang lại $cd->cat_name;get_the_category




function wp_get_post_categories( $post_id = 0, $args = array() ) $post_id = (int) $post_id; $defaults = array("" => ""; $args = wp_parse_args( $args, $defaults ); $cats = wp_get_object_terms($post_id, "", $args); return $cats;Here is the second argument of function wp_get_post_categories() which you can pass the attributes of receiving data.

$category_detail = get_the_category( "",array( "" => "" ) ); //$post->IDforeach( $category_detail as $cd ) emang lại $cd->name;

Xem thêm: Garena Kết Nối Lỗi Vui Lòng Thử Lại, Kết Nối Lỗi Vui Lòng Thử Lại Garena

Use get_the_category() function.

$post_categories = wp_get_post_categories( 4 );$categories = get_the_category($post_categories<0>);var_dump($categories);
term_id; $cat->name; ?> term_id, "", true ); $image = wp_get_attachment_url( $thumbnail_id ); if ( $image ) emang đến "

"; }?>
Thanks for contributing an answer to lớn Staông xã Overflow!

Please be sure to answer the question. Provide details & nội dung your research!

But avoid

Asking for help, clarification, or responding khổng lồ other answers.Making statements based on opinion; baông xã them up with references or personal experience.

To learn more, see our tips on writing great answers.

Post Your Answer Discard

By clicking “Post Your Answer”, you agree khổng lồ our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged php wordpress categories or ask your own question.

mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 khổng lồ be resource

Xem thêm: Hướng Dẫn Cách Xóa Chuyên Mục Trong Wordpress Mới Nhất 2020

site thiết kế / hình ảnh © 2021 Stachồng Exchange Inc; web1_user contributions licensed under cc by-sa. rev2021.5.7.39232

Your privacy

By clicking “Accept all cookies”, you agree Stachồng Exchange can store cookies on your device & discthua trận information in accordance with our Cookie Policy.

Chuyên mục: Lỗi Kỹ Thuật