Find Category ID of post, see if it equals 20, then do something
-
I am trying to find the categories of a post, and see if one of them is a specific id. If it is… do something. ELSE, do something else.
My logic is that I need to build a list of the IDs for a post. Then I need to see if one of those IDs is 20. Then do the if/else.
What is wrong with my code below? This is in the loop by the way.
<?php
foreach ((get_the_category()) as $cat) {
$my_cat .= $cat->category_id . ',';
}
echo $my_cat; //FOR DEBUGGINGif ($my_cat == '20') { ?>
<p>DO SOMETHING</p>
<?php } else { ?>
<p>DO SOMETHING ELSE</p>
<?php } ?>
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Find Category ID of post, see if it equals 20, then do something’ is closed to new replies.