dimanche 1 février 2015

Get the ID of category page with or without any posts


Is there a better way to get the category ID that may or may not have any posts assigned to it?


Currently im using the following code that resorts to parsing the page url, and getting the category ID from its slug. Doesn't feel like the best way to do it.



$current_url = rtrim($_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"], "/");
$arr_current_url = split("/", $current_url);
$thecategory = get_category_by_slug( end($arr_current_url) );
$catid = $thecategory->term_id;




Aucun commentaire:

Enregistrer un commentaire