Skip to content

Commit b7520e2

Browse files
committed
Remove category from old posts
1 parent 57f595e commit b7520e2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
// Execute this hook with a cron job
4+
add_action('my_remove_cats', 'my_remove_cats_exec');
5+
function my_remove_cats_exec() {
6+
$posts = get_posts([
7+
'numberposts' => -1,
8+
'category_name' => 'slug-of-cat-to-remove',
9+
'date_query' => [
10+
'after' => date("Y-m-d H:i:s", strtotime('-180 days', current_time('timestamp'))),
11+
]
12+
]);
13+
14+
if(!empty($posts)) {
15+
foreach($posts as $post) {
16+
wp_remove_object_terms($post->ID, 'slug-of-cat-to-remove', 'category');
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)