dedicated chantier page
This commit is contained in:
parent
2c1d9a3241
commit
41abd525f5
|
|
@ -6,6 +6,7 @@ require_once(__DIR__ . '/includes/errorlog.php');
|
|||
require_once(__DIR__ . '/includes/init.php');
|
||||
require_once(__DIR__ . '/includes/post_types.php');
|
||||
require_once(__DIR__ . '/includes/artisans.php');
|
||||
require_once(__DIR__ . '/includes/chantiers.php');
|
||||
require_once(__DIR__ . '/includes/admin.php');
|
||||
require_once(__DIR__ . '/includes/taxonomy.php');
|
||||
require_once(__DIR__ . '/includes/api.php');
|
||||
|
|
|
|||
72
includes/chantiers.php
Normal file
72
includes/chantiers.php
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<?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);
|
||||
Loading…
Reference in New Issue
Block a user