Having trouble retrieving category ID with get_cat_ID()
-
I’m having trouble retrieving category ID’s using the get_cat_ID() function. I have a number of categories such as “Monday Specials”, “Tuesday Specials” etc (one for each weekday) with content in each category. When I pass in a literal string to the get_cat_ID() function (e.g. Tuesday Specials) I get the category ID returned properly but when I pass in a variable I get 0 returned which I understand to mean that the function failed. When I print the variable it displays fine so I don’t understand why this function is not working. (In case it matters I’m using the Shortcode PHP Exec plugin to execute the code via a shortcode in a page and the Easy Timer plugin to retrieve the current weekday and date (in the local users’s timezone).
Here is a code snippet:
[please use the ‘code’ button to mark your code]
~ ~ ~
extract (shortcode_atts(array('region' => 'All Neighborhoods'), $atts)); $curr_weekday = '[weekday]'; // get the weekday from the other plugin since it's working properly echo 'Today is ' . $curr_weekday . '.'; //this works properly $weekdayspecials = $curr_weekday . ' Specials'; // e.g. Tuesday Specials echo 'weekdayspecials=' . $weekdayspecials . ''; // displays the correct string $category_id = get_cat_ID( $weekdayspecials ); //This returns 0 (doesn't work) $category_id = get_cat_ID( 'Tuesday Specials' ); //This works (returns proper category id)
~ ~ ~
I cannot figure out why it is only working properly when I am passing in the literal string (which I don’t want to do). This is driving me crazy. Please help! Thanks! ?? (I am a programmer but new to PHP so I’m sure there are things I’m just not getting yet…)
Corinne
- The topic ‘Having trouble retrieving category ID with get_cat_ID()’ is closed to new replies.