Getting current category ID
-
Is there an easier way of getting the current category ID? (Without having to access the database)
<?php $cat_rows = $wpdb->get_results("SELECT term_id FROM wp_term_taxonomy WHERE taxonomy = 'category'"); foreach ($cat_rows as $cat_row) { if( is_category( $cat_row->term_id ) ){ $what_i_am_looking_for = $cat_row->term_id; echo 'The current category ID is: ' . $what_i_am_looking_for; } } ?>
Here I’m getting all the categories from the database and I’m testing whether or not each of them is the current category… not very effective…
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Getting current category ID’ is closed to new replies.