Created
June 4, 2014 14:12
-
-
Save m-e-h/4c4344a4ce6c48630aca to your computer and use it in GitHub Desktop.
bidirectional with user and post -pods
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
add_action( 'pods_api_post_save_pod_item', 'slug_user_fix', 10, 3); // Needed to add the params number | |
function slug_user_fix( $pieces, $is_new_item, $id ) { | |
if ( isset( $pieces[ 'fields' ][ 'FIELD_REALTED_TO_USERS' ][ 'value' ] ) ) { | |
$uIDs = explode(",", $pieces[ 'fields' ][ 'FIELD_RELATED_TO_USERS' ][ 'value' ]); | |
// Check that we have some uIDs to work with. | |
if (false === empty($uIDs)) { | |
// Loop through, converting to integers and verifying the conversion | |
foreach($uIDs as $uID) { | |
$uID = (int)$uID; | |
if (is_int($uID)) { | |
if (get_user_by('id', $uID) !== false) { | |
$value = get_user_meta($uID, 'RELATED_FIELD_IN_USERS_NAME.ID'); | |
$value[] = $id; | |
update_user_meta($uID, 'RELATED_FIELD_IN_USERS_NAME', $value); | |
} | |
} | |
} | |
} | |
} | |
return $pieces; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment