Category_id switch
-
I am trying to mail using a php switch structure according to category ID but I can’t seem to properly extract the ID that I am comparing, I am looking at the url /term.php?taxonomy=category&tag_ID=44 to get the actual ID I need but I always drop out of the bottom of the switch without evaluating true (herewith an abbreviated example). What am I doing wrong?
$categories = get_the_category($post_id); if ( ! empty( $categories ) ) { $category_id =( $categories[0]-> term_id ); } switch ($category_id) { case 44 : //"Announcements": $mailgun_listaddress = "[email protected]"; $subject = "An Announcement from CLE term8id=". $category_id; wp_mail( '[email protected]', $subject, $message ); break; case 9 : //"News": $mailgun_listaddress = "[email protected]"; $subject = "News from CLE". $category_id; wp_mail( '[email protected]', $subject, $message ); break; default: $mailgun_listaddress = "[email protected]"; $subject = 'An unhandled post has been posted - id:'. $category_id; wp_mail( '[email protected]', $subject, $message ); }
- This topic was modified 7 years, 6 months ago by . Reason: put code in backticks; moved to fixing from developing
The page I need help with: [log in to see the link]
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Category_id switch’ is closed to new replies.