Category ID returns as ‘0’?

Question

I’m trying to populate the category id from the category name within the loop.

    <?php $cat_name = get_theme_mod( 'cat_1' ); ?>
    <?php $category_id = get_cat_ID($cat_name); ?>
    <?php query_posts('cat='.$category_id); ?>

the cat_1 theme mod is a category dropdown I have in the theme customizer that gets and lists category names in a dropdown list. Currently, my loop is showing all posts from all categories instead of the category selected from theme_mod cat_1.

When I use:

    <h4><?php echo $category_id; ?></h4>

it returns as ‘0’ instead of the id of the category when selected from the category dropdown (theme mod cat_1).

0
, user3350469 7 years 2015-10-30T18:25:51-05:00 0 Answers 52 views 0

Leave an answer

Browse
Browse