Created
September 8, 2015 05:54
-
-
Save Ciantic/b6ef49f0358bf913f394 to your computer and use it in GitHub Desktop.
Insert or Get Term ID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * (WordPress) Insert or get term id | |
| * | |
| * @return int Term ID (0 no term was inserted or found) | |
| */ | |
| function __wp_insert_or_get_term_id($name, $taxonomy, $parent = 0) { | |
| if (!($term = get_term_by("name", $name, $taxonomy))) { | |
| $insert = wp_insert_term($name, $taxonomy, array( | |
| "parent" => $parent | |
| )); | |
| if (is_wp_error($insert)) { | |
| return 0; | |
| } | |
| return intval($insert["term_id"]); | |
| } | |
| return intval($term->term_id); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment