73 lines
2.0 KiB
PHP
73 lines
2.0 KiB
PHP
<?php
|
|
|
|
/* ---------------------------
|
|
CUSTOM CHANTIER META BOX AT THE END OF THE PAGE
|
|
---------------------------*/
|
|
add_action('add_meta_boxes', function () {
|
|
// Ajout de la metabox uniquement pour le post type 'artisans'
|
|
add_meta_box(
|
|
'admin_chantier_artisan_ref', // ID de la metabox
|
|
'Artisan du chantier', // Titre de la metabox
|
|
'render_artisan_box_content', // Fonction de rendu
|
|
'chantiers', // Post type
|
|
'normal', // Contexte
|
|
'high' // Priorité
|
|
);
|
|
});
|
|
|
|
/**
|
|
* Fonction de rendu du contenu de la metabox.
|
|
*/
|
|
function render_artisan_box_content($post)
|
|
{
|
|
|
|
$args = array(
|
|
'post_type' => 'chantiers',
|
|
'posts_per_page' => -1,
|
|
'post_status' => 'publish',
|
|
'meta_query' => array(
|
|
array(
|
|
'key' => 'artisan',
|
|
'value' => $post->ID,
|
|
'compare' => '=',
|
|
),
|
|
),
|
|
);
|
|
|
|
$chantiers = new WP_Query($args);
|
|
|
|
|
|
// Afficher les chantiers
|
|
|
|
if ($chantiers->have_posts()) {
|
|
|
|
echo '<ul>';
|
|
while ($chantiers->have_posts()) {
|
|
$chantiers->the_post();
|
|
$chantier_name = get_field('chantier_name');
|
|
echo '<li><a href="' . get_edit_post_link() . '"> <img src=' . get_stylesheet_directory_uri() . '/resources/img/icons/document-inspect.svg' . ' /> ' . $chantier_name . '</a></li>';
|
|
}
|
|
echo '</ul>';
|
|
} else {
|
|
echo '<p style="font-size: 1rem;">Ce chantier n\'est relié à aucun artisan</p>';
|
|
}
|
|
}
|
|
|
|
|
|
add_action('acf/render_field', function ($field) {
|
|
// Vérifiez si le champ est celui que vous voulez personnaliser
|
|
if ($field['key'] === 'field_6719065f58122') {
|
|
if (did_action('acf/render_field/key=field_6719065f58122') % 2 === 0) {
|
|
return;
|
|
}
|
|
$field['rendered'] = true;
|
|
|
|
$linked_post_id = get_field($field['key']);
|
|
|
|
if ($linked_post_id) {
|
|
$edit_link = get_edit_post_link($linked_post_id);
|
|
echo '<a href="' . esc_url($edit_link) . '" target="_blank" class="edit-fiche-artisan-link"><img src=' . get_stylesheet_directory_uri() . '/resources/img/icons/tools.svg' . ' /> Voir la fiche de l\'artisan </a>';
|
|
}
|
|
}
|
|
}, 10, 1);
|