WordPress get all category id’s

To get all the category id’s from current wordpress blog you have to use following function which returns an array of all the category id’s

1
<?php $all_category_ids=get_all_category_ids() ?>

after that you can fetch to retrieve all the category ids. even you can get category name for each category.

1
2
3
4
5
6
7
<?php
$category_ids = get_all_category_ids();
foreach($category_ids as $cat_id) {
  $cat_name = get_cat_name($cat_id);
  echo $cat_id ': ' $cat_name.'<br />';
}
?>
Read Also :  Wordpress Use Shortcode outside post editor in theme files

Be the first to comment

Leave a Reply

Your email address will not be published.


*