Thanks Eliot. Works for me !
Hi, I have the same problem so I went back to the old version. I updated my post, recreates relationship, reinstall the plugin, but can not save the value of the relationship. the var_dump() function and print_r() returns an empty array.
I use a custom post type “profile” and another “card”. The first allows you to add information about a cosplay (username, first name, date of birth, profile picture, etc..). Thereafter, another custom post type “gallery-cosplay”, allows me to add galleries for each cosplay. You can see an example at: http://shingo-temple.fr/galleries-de-cosplay
So I wrote two functions. The first allows you to change the title of the gallery with the nickname and the name of the gallery:
add_action('save_post', 'modify_post_title');
function modify_post_title($post_id) {
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return;
if ( ! wp_is_post_revision( $post_id ) ) {
if('cosplay-gallery' == get_post_type($post_id) && get_field('card', $post_id)) {
foreach(get_field('card') as $post_object) {
$value = get_field('pseudo', $post_object->ID);
$post_title = $value.' : '.get_field('gallery_name', $post_id);
}
}
}
if('acf' != get_post_type($post_id)) {
if ($post_title == '') { $post_title = $_POST['post_title'];}
remove_action('save_post', 'modify_post_title');
$arg = array();
$arg['ID'] = $post_id;
$arg['post_title'] = $post_title;
wp_update_post( $arg );
add_action('save_post', 'modify_post_title');
}
}
The second is to change the permalink:
function append_slug($data) {
global $post_id;
if('cosplay-gallery' == get_post_type($post_id) && get_field('card', $post_id)) {
foreach(get_field('card') as $post_object) {
$value = get_field('pseudo', $post_object->ID);
$slug = $value.' : '.get_field('gallery_name', $post_id);
}
if ($data['post_name'] != $slug) {
$data['post_name'] = sanitize_title($slug, $post_ID);
}
} else {
if ($data['post_name'] != $data['post_title']) {
$data['post_name'] = sanitize_title($data['post_title'], $post_ID);
}
}
return $data;
}
For now, I must save a draft for it to work. Moreover, when I upload images of cosplay, they are renamed “$pseudo.’-‘. $gallery.’-‘.45646.jpg”. If I do not save the draft, it is impossible to have the nickname of cosplay, or the name of the gallery because I use a custom relationship field that points to the profile and custom text field where i write the name of the gallery.
Ditto for custom post type “card”. This allow gather all the information about a game and share them with other custom post types “review” and “preview”. So I need to retrieve the information in the custom field before they are stored in the database.
edit: I analyzed the source code of the admin. I could see where the value to retrieve. It remains for me to understand how to use this value with jquery. Thank you!
Thank you for your reply. I have a custom field image, but I want the image file is renamed during the upload. For example, when I upload an image to a custom post type review, it automatically renames the file “gears-of-war xbox-360-review-4565.jpg” or “gears-of-war-xbox-360-preview.jpg “. So I would like for a cover, the file is automatically renamed as “gears-of-war-xbox-360-cover.” Should therefore add a piece of code that determines if the upload is done from the custom field image “cover” and add “cover” in the new filename.
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.