Have you ever wanted to find out certain category ID by its name or maybe do that in reverse? Maybe I’m missing something but there’s no method to achieve that via built-in WordPress functions so here is quick and dirty way of getting category ID by category name and vice versa.
<?php
$category_slug = "myCategory"; // just an example name/slug
$category_ID = $wpdb->get_var( "SELECT term_id FROM $wpdb->terms WHERE slug = '" . $category_slug . "'" );
?>
<?php
$category_ID = 1; // just an example ID
$category_name = $wpdb->get_var( "SELECT name FROM $wpdb->terms WHERE term_id = " . $category_id );
?>
I guess you should find out category slug first. It's a little bit longer way, maybe I'm wrong...
Subscribe to RSSStay up to date with my blog
Follow me!Follow me or get followed
iPadCaseDen.comiPad cases, folio cases and bags review