Compare commits
2 Commits
961111067e
...
5624335a79
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5624335a79 | ||
|
|
ef468b323f |
|
|
@ -17,6 +17,7 @@ require_once(__DIR__ . '/includes/equipe.php');
|
||||||
require_once(__DIR__ . '/includes/navwalker.php');
|
require_once(__DIR__ . '/includes/navwalker.php');
|
||||||
require_once(__DIR__ . '/includes/post-type-analyses-etudes.php');
|
require_once(__DIR__ . '/includes/post-type-analyses-etudes.php');
|
||||||
require_once(__DIR__ . '/includes/posts-save.php');
|
require_once(__DIR__ . '/includes/posts-save.php');
|
||||||
|
require_once(__DIR__ . '/includes/auteurs.php');
|
||||||
// require_once(__DIR__ . '/includes/widget.php');
|
// require_once(__DIR__ . '/includes/widget.php');
|
||||||
// require_once( __DIR__ . '/includes/taxonomy.php');
|
// require_once( __DIR__ . '/includes/taxonomy.php');
|
||||||
// require_once( __DIR__ . '/includes/errorlog.php');
|
// require_once( __DIR__ . '/includes/errorlog.php');
|
||||||
|
|
|
||||||
44
includes/auteurs.php
Normal file
44
includes/auteurs.php
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
add_action('acf/save_post', 'carhop_save_auteurs_post');
|
||||||
|
|
||||||
|
function carhop_save_auteurs_post($post_id)
|
||||||
|
{
|
||||||
|
$post_type = get_post_type($post_id);
|
||||||
|
|
||||||
|
if ($post_type !== 'auteurs') return;
|
||||||
|
|
||||||
|
$is_carhop_member = $_POST['acf']['field_6997373d4aacd'];
|
||||||
|
$carhop_member_id = $_POST['acf']['field_6997373d4aad1'] ?? null;
|
||||||
|
|
||||||
|
if ($carhop_member_id === 0) return;
|
||||||
|
|
||||||
|
$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);
|
||||||
|
restore_current_blog();
|
||||||
|
|
||||||
|
update_field('first_name', $first_name, $post_id);
|
||||||
|
update_field('last_name', $last_name, $post_id);
|
||||||
|
}
|
||||||
|
$full_name = $first_name . ' ' . $last_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,
|
||||||
|
'post_title' => $full_name,
|
||||||
|
'post_name' => $post_slug
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -379,26 +379,38 @@ function get_authors_linked_to_posts(array $post_ids)
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
$author_ids = array();
|
$author_ids = array();
|
||||||
|
|
||||||
foreach ($post_ids as $post_id) {
|
foreach ($post_ids as $post_id) {
|
||||||
$post_authors = get_field('authors', $post_id);
|
$post_authors = get_field('authors', $post_id);
|
||||||
if (empty($post_authors)) continue;
|
|
||||||
|
|
||||||
foreach ($post_authors as $author) {
|
$has_main_author = get_field('has_main_author', $post_id);
|
||||||
$author_id = is_object($author) ? $author->ID : (int) $author;
|
$post_main_author = get_field('main_author', $post_id);
|
||||||
if ($author_id) {
|
|
||||||
$author_ids[$author_id] = $author_id; // set pour éviter les doublons
|
if (!empty($post_authors)) {
|
||||||
|
foreach ($post_authors as $author) {
|
||||||
|
$author_id = is_object($author) ? $author->ID : (int) $author;
|
||||||
|
if ($author_id) {
|
||||||
|
$author_ids[$author_id] = $author_id; // set pour éviter les doublons
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($has_main_author && is_object($post_main_author) && isset($post_main_author->ID)) {
|
||||||
|
$author_ids[$post_main_author->ID] = $post_main_author->ID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (empty($author_ids)) {
|
if (empty($author_ids)) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
return get_posts(array(
|
return get_posts(array(
|
||||||
'post_type' => 'auteurs',
|
'post_type' => 'auteurs',
|
||||||
'post__in' => array_values($author_ids),
|
'post__in' => array_values($author_ids),
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
'orderby' => 'title',
|
|
||||||
'order' => 'ASC',
|
'order' => 'ASC',
|
||||||
|
'meta_key' => 'last_name',
|
||||||
|
'orderby' => 'meta_value',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user