Skip to content

Instantly share code, notes, and snippets.

@quimo
Created June 12, 2017 15:17
Show Gist options
  • Save quimo/e3e9bf3e3d39e901587837fa0f7793f8 to your computer and use it in GitHub Desktop.
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
<?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