Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SET TAXONOMY OF AUTHOR
- add_action('gform_post_submission', 'ounce_gform_post_submission', 10, 2);
- function ounce_gform_post_submission($entry, $form) {
- // if no post was created, return
- if(!$entry['post_id'])
- return;
- // name_ID = the ID of the author in the author custom taxonomy
- if ($entry["1"] == 'Poe') {
- $name_ID = "12";
- } elseif ($entry["1"] == 'King') {
- $name_ID = "24";
- } elseif ($entry["1"] == 'Lewis') {
- $name_ID = "48";
- } elseif ($entry["1"] == 'Tolkien') {
- $name_ID = "96";
- }
- $term_id = $name_ID;
- // the slug name of the taxonomy you set up
- $taxonomy = 'author';
- // if we have a taxonomy and a field id, add term to post
- if($taxonomy && $term_id)
- ounce_add_term_to_post($taxonomy, $term_id, $entry['post_id']);
- }
- // add term from taxonomy to post
- function ounce_add_term_to_post($taxonomy = "categories", $term_id, $post_id) {
- $terms = get_terms($taxonomy, array('hide_empty' => 0));
- foreach($terms as $term) {
- if($term->term_id == $term_id)
- $result = wp_set_object_terms($post_id, (int) $term_id, $taxonomy, false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement