FEATURE handling new carhiop member synchronisation

This commit is contained in:
Nonimart 2025-11-25 16:00:27 +01:00
parent 5d14c64fa8
commit 98f628a05a
2 changed files with 78 additions and 12 deletions

View File

@ -44,13 +44,47 @@ function dynamiques_save_auteurs_post($post_id)
{
$post_type = get_post_type($post_id);
if ($post_type == 'auteurs') {
$first_name = get_field('first_name', $post_id) ?? '';
$last_name = get_field('last_name', $post_id) ?? '';
if ($post_type !== 'auteurs') return;
$is_carhop_member = $_POST['acf']['field_691c8279b6458'];
$carhop_member_id = $_POST['acf']['field_691c831e94029'] ?? null;
$first_name = null;
$last_name = null;
if (!$is_carhop_member) {
$first_name = get_field('first_name', $post_id);
$last_name = get_field('last_name', $post_id);
}
if (isset($is_carhop_member) && isset($carhop_member_id)) {
switch_to_blog(1);
$first_name = get_field('first_name', $carhop_member_id);
$last_name = get_field('last_name', $carhop_member_id);
$comity = get_field('comity', $carhop_member_id);
write_log($comity);
// $membre_carhop = get_post($carhop_member_id);
// write_log($_POST['acf']);
// $description = get_field('description', $carhop_member_id);
// $comity = get_field('comity', $carhop_member_id);
// $email = get_field('email', $carhop_member_id);
// write_log($first_name);
// write_log($last_name);
// write_log($description);
// write_log($email);
$display_name = $first_name . ' ' . $last_name;
restore_current_blog();
update_field('comity', $comity, $post_id);
}
$full_name = $first_name . ' ' . $last_name;
if ($full_name && $full_name != '') {
if (isset($first_name) && isset($last_name) && isset($full_name) && $full_name != '') {
$post_slug = sanitize_title($full_name);
wp_update_post(array(
'ID' => $post_id,
@ -58,5 +92,26 @@ function dynamiques_save_auteurs_post($post_id)
'post_name' => $post_slug
));
}
}
}
add_filter('acf/load_field/name=carhop_member', function ($field) {
$field['choices'] = [];
switch_to_blog(1);
$equipe_members = get_posts(array(
'post_type' => 'equipe',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
));
restore_current_blog();
foreach ($equipe_members as $equipe_member) {
$field['choices'][$equipe_member->ID] = $equipe_member->post_title;
}
return $field;
});

View File

@ -7,6 +7,17 @@ $profilePictureUrl = $profilePicture['url'] ?? '';
$profilePictureAlt = $profilePicture['alt'] ?? '';
$description = get_field('description', $ID);
$is_carhop_member = get_field('is_carhop_member', $ID);
$carhop_member_id = get_field('carhop_member', $ID);
if ($is_carhop_member && isset($carhop_member_id)) {
switch_to_blog(1);
$description = get_field('description', $carhop_member_id);
restore_current_blog();
}
write_log($is_carhop_member);
$totalArticles = count_user_articles($ID, 'articles');
?>