Home › Forums › Add-ons › Repeater Field › Save ACF relationship (name) value to ACF text field › Reply To: Save ACF relationship (name) value to ACF text field
Hello John!
Thanks very much for your help!
I have tried to set up a function with your changes as follows:
<?php
//Make special artist field autosave for sorting
function write_artist_name_to_hidden( $post_id ) {
//Get the value of the relationhip field, unformatted, from the project post being saved.
$kuenstlerinnen_id = get_field ('project_to_kunstlerin', $post_id, false);
//The above value could be an array
if (is_array('kuenstlerinnen_id')) {
$kuenstlerinnen_id = kuenstlerinnen_id[0];
}
//get the last name field from the other post
$artist_nachname = get_field('artist_nachname', $kuenstlerinnen_id);
//update the field on the project with this value
update_field('project_kunstlerin_nach_name_sort', $artist_nachname, $post_id);
}
add_action('acf/save_post', 'write_artist_name_to_hidden', 11);
Sadly I am doing something wrong here, as get several warnings when I try to update a post:
Warning: Illegal offset type in isset or empty in /Users/sebastianalbert/Local Sites/fotohof-calling/app/public/wp-content/plugins/advanced-custom-fields-pro/includes/local-meta.php on line 195
Warning: Illegal offset type in isset or empty in /Users/sebastianalbert/Local Sites/fotohof-calling/app/public/wp-content/plugins/acf-extended/includes/core/meta.php on line 168
Warning: Illegal offset type in isset or empty in /Users//Local Sites/fotohof-calling/app/public/wp-content/plugins/advanced-custom-fields-pro/includes/local-meta.php on line 195
Warning: Illegal offset type in isset or empty in /Users//Local Sites/fotohof-calling/app/public/wp-content/plugins/acf-extended/includes/core/meta.php on line 168
Warning: Cannot modify header information – headers already sent by (output started at /Users//Local Sites/fotohof-calling/app/public/wp-content/plugins/advanced-custom-fields-pro/includes/local-meta.php:195) in /Users//Local Sites/fotohof-calling/app/public/wp-includes/pluggable.php on line 1340
Warning: Cannot modify header information – headers already sent by (output started at /Users//Local Sites/fotohof-calling/app/public/wp-content/plugins/advanced-custom-fields-pro/includes/local-meta.php:195) in /Users//Local Sites/fotohof-calling/app/public/wp-includes/pluggable.php on line 1343
Do you have any idea what I am doing wrong here? I am pretty new to the php stuff.
Thanks again for your help!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.