WordPress does not have a builtin function named get_all_category_ids()
. However, you can easily retrieve all category IDs by using a custom function that queries the WordPress database. Here's an example of how you can create such a function:
function get_all_category_ids() {
$args = array(
'taxonomy' => 'category',
'hide_empty' => false,
);
$categories = get_categories($args);
$category_ids = array();
foreach ($categories as $category) {
$category_ids[] = $category>term_id;
}
return $category_ids;
}
Here's how this function works:
It defines an array of arguments for the get_categories()
function. The taxonomy
argument is set to 'category'
, and hide_empty
is set to false
to include categories that have no posts.
It calls get_categories()
to retrieve all categories based on the provided arguments.
It loops through the returned categories, extracts the term_id
(which is the category ID), and adds it to an array.
Finally, it returns the array of category IDs.
You can use this get_all_category_ids()
function in your WordPress theme or plugin to get an array of all category IDs on your site.