FEATURE Enlarging post numerotation handling to more post types and usiong a reusable function
This commit is contained in:
parent
cea500ceda
commit
52f988c72d
17
includes/posts-save.php
Normal file
17
includes/posts-save.php
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
function handle_posts_numerotation_remapping_on_save()
|
||||||
|
{
|
||||||
|
$post_type = get_post_type();
|
||||||
|
|
||||||
|
$numerotated_post_types = array('analyses-etudes', 'expositions', 'outils-pedagogiques', 'recherches');
|
||||||
|
// Ne s'exécuter que dans l'admin pour éviter de surcharger le frontend
|
||||||
|
if (!is_admin() || !in_array($post_type, $numerotated_post_types)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handle_posts_numerotation_remapping($post_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
add_action('save_post', 'handle_posts_numerotation_remapping_on_save');
|
||||||
|
add_action('delete_post', 'handle_posts_numerotation_remapping_on_save');
|
||||||
|
|
@ -62,6 +62,29 @@ function get_archive_page_subtitle_html($post_type)
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function handle_posts_numerotation_remapping($post_type)
|
||||||
|
{
|
||||||
|
if (!is_admin()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = new WP_Query(array(
|
||||||
|
'post_type' => $post_type,
|
||||||
|
'posts_per_page' => -1,
|
||||||
|
'orderby' => 'date',
|
||||||
|
'order' => 'ASC',
|
||||||
|
));
|
||||||
|
$numerotation = 0;
|
||||||
|
while ($query->have_posts()) {
|
||||||
|
$query->the_post();
|
||||||
|
$numerotation++;
|
||||||
|
update_post_meta(get_the_ID(), 'post_numerotation', $numerotation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function hasPostTypeNumerotation($post_type)
|
function hasPostTypeNumerotation($post_type)
|
||||||
{
|
{
|
||||||
switch ($post_type) {
|
switch ($post_type) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user