Tell us what you are trying to do? Run a custom code snippet that loops through related child posts of a parent post
Is there any documentation that you are following? No
Is there a similar example that we can see? No
What is the link to your site?
I am currently running the following custom code snippet for a CRED form that edits a custom post type:
$salons = array( $salon1, $salon2, $salon3 );
if ( in_array( 'complete', $salons ) ) {
wp_set_post_terms( $post_id, 'local', 'tax-salon-location' );
} else {
wp_set_post_terms( $post_id, 'national', 'tax-salon-location' );
The above code snippet works just fine until I add it to another CRED form function that loops through related posts. The following code doesn't update the post taxonomy as expected. Cleary, I'm doing something wrong. Here is the other code snippet:
if ( $form_data['id']==1444 ) {
$related_owners = toolset_get_related_posts( $post_id, 'salon-related-owner', 'parent' );
$salons = array();
foreach ( $related_owners as $related_owner ) {
$salon_name1 = get_post_meta( $related_owner, 'wpcf-post-salon-name1', true );
$salon_name2 = get_post_meta( $related_owner, 'wpcf-post-salon-name2', true );
$salon_name3 = get_post_meta( $related_owner, 'wpcf-post-salon-name3', true );
$salon_details1 = get_post_meta( $related_owner, 'wpcf-post-salon-details1', true );
$salon_details2 = get_post_meta( $related_owner, 'wpcf-post-salon-details2', true );
$salon_details3 = get_post_meta( $related_owner, 'wpcf-post-salon-details3', true );
if ( !empty($salon_name1) && !empty($salon_details1) ) {
$salon1 = 'complete';
}
if ( !empty($salon_name2) && !empty($salon_details2) ) {
$salon2 = 'complete';
}
if ( !empty($salon_name3) && !empty($salon_details3) ) {
$salon3 = 'complete';
}
$salons = array( $salon1, $salon2, $salon3 );
if ( in_array( 'complete', $salons ) {
wp_set_post_terms( $related_owner, 'local', 'tax-salon-location' );
} else {
wp_set_post_terms( $related_owner, 'national', 'tax-salon-location' );
}
}
}
Any assistance would be greatly appreciated. Thank you in advance!