Created
June 12, 2017 15:17
-
-
Save quimo/e3e9bf3e3d39e901587837fa0f7793f8 to your computer and use it in GitHub Desktop.
WP | Cambiare la categoria di un post dopo un dato lasso di tempo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function changeCategory() { | |
define('MOVE_TIME_LIMIT', 432000); /* 5 giorni in secondi */ | |
$args = array( | |
'category_name' => 'Categoria1' | |
); | |
$query = new WP_query ($args); | |
if ($query->have_posts()) { | |
while ($query->have_posts()) { | |
$query->the_post(); | |
$seconds = current_time( 'timestamp' ) - get_the_time('U'); | |
/* se sono passati 5 giorni */ | |
if ($seconds > MOVE_TIME_LIMIT) { | |
/* modifico la categoria del post */ | |
wp_set_post_categories( get_the_ID(), array(36)); | |
} | |
} | |
} | |
wp_reset_query(); | |
wp_reset_postdata(); | |
} | |
add_action('init', changeCategory); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment