0

I have a categories and I have to display all categories id along with categories name.

Something like

Accessories(id=1)

featured(id=1)

OR

id  Name
1   Accessories
2   featured

enter image description here Is it possible to display without a plugin?

1 Answer 1

1

You can add new column using below code. replace (your-texanomy) with your taxonomy slug. I have tested and its working fine. https://prnt.sc/qbibg0

#add header before category name
function taxonomy_custom_column_header( $columns ){

    $columns = array_slice($columns, 0, 1, true) +
    array("cat_id" => "ID") +
    array_slice($columns, 1, count($columns) - 1, true) ;

    return $columns;
}
add_filter( "manage_edit-(your-texanomy)_columns", 'taxonomy_custom_column_header', 10);

# add value to newly added column
function taxonomy_custom_column_content( $value, $column_name, $tax_id ){

    if ( 'cat_id' == $column_name ) {
        $content = $tax_id;
    }
    return $content;
}
add_action( "manage_(your-texanomy)_custom_column", 'taxonomy_custom_column_content', 10, 3);
13
  • Give me some time to check this. Dec 16, 2019 at 12:39
  • I need to know why you use 10, 3 in add_action? Dec 16, 2019 at 12:40
  • 1
    Yes, It's working in category. I have a doubt. I have created custom post type and I am getting the list some think like this prnt.sc/qbiyn4. Now if I have to displaying categorywith id then How can I display? somethink like Product-slider1-mycatgoryid Dec 16, 2019 at 13:17
  • 1
    The answer works as you say yourself @NarenVerma, the ID is visible on the category listing. What you now suddenly also want is it be shown on the post type listing, which is another(extra) question. Perhaps you open a new question with this as question.
    – Charles
    Dec 16, 2019 at 13:40
  • 1
    There is no doubt, it works as asked, what you want now also is a little more 'complex'/different. Question for new topic could be: How to display the Cat ID on a custom post type listing
    – Charles
    Dec 16, 2019 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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