Last active
April 1, 2020 03:41
-
-
Save vfontjr/e5526352c2140cecb446445cfbfaa064 to your computer and use it in GitHub Desktop.
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 | |
add_action( 'frm_after_create_entry', 'create_new_cpt_taxonomy', 30, 2 ); | |
function create_new_cpt_taxonomy( $entry_id, $form_id ) { | |
/* first thing to do is to make sure this runs on the correct form */ | |
if( $form_id == 32 ) { //change 32 to the ID of your form | |
if( isset( $_POST['item_meta'][254] ) ) { //change 254 to the ID of the field used to add a category | |
$taxonomy = 'city'; //if you're using a custom taxonomy, change this to the correct name | |
$term = $_POST['item_meta'][254]; | |
/* first retrieve the entry object */ | |
$entry = FrmEntry::getOne( $entry_id ); | |
/* if there's no post_id, exit the function. There's nothing for us to do */ | |
if ( ! $entry->post_id ) { | |
return; | |
} else { | |
/* make the association */ | |
wp_set_object_terms( $entry->post_id, $term, $taxonomy, true ); | |
} | |
} | |
} | |
} |
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 | |
add_action( 'frm_after_create_entry', 'create_new_cpt_taxonomy', 30, 2 ); | |
function create_new_cpt_taxonomy( $entry_id, $form_id ) { | |
switch( $form_id ) { | |
case 32 : | |
if( isset( $_POST['item_meta'][254] ) ) { | |
$term = $_POST['item_meta'][254]; | |
$taxonomy = 'city'; | |
process_new_cpt_taxonomy( $entry_id, $taxonomy, $term ); | |
} | |
break; | |
case xx : // second form id | |
if( isset( $_POST['item_meta'][xxx] ) ) { | |
$term = $_POST['item_meta'][xxx]; | |
$taxonomy = 'city'; | |
process_new_cpt_taxonomy( $entry_id, $taxonomy, $term ); | |
} | |
break; | |
} | |
} | |
function process_new_cpt_taxonomy( $entry_id, $taxonomy, $term ) { | |
/* first retrieve the entry object */ | |
$entry = FrmEntry::getOne( $entry_id ); | |
/* if there's no post_id, exit the function. There's nothing for us to do */ | |
if ( ! $entry->post_id ) { | |
return; | |
} else { | |
/* make the association */ | |
wp_set_object_terms( $entry->post_id, $term, $taxonomy, true ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment