Files
feadulta/scripts/quitar_multimedia.php

15 lines
758 B
PHP

<?php
// #4: quita la categoría Multimedia (1649 + traducciones) de los posts-lectura.
$multi=[1649];
foreach(["en","fr","it","pt"] as $L){ $t=pll_get_term(1649,$L); if($t)$multi[]=(int)$t; }
global $wpdb;
$rows=$wpdb->get_results("SELECT ID FROM {$wpdb->posts} WHERE post_type='post' AND post_status='publish' AND post_title REGEXP '[0-9]+, *[0-9]+(-[0-9]+)?\\.?$'");
$feadulta=(int)$wpdb->get_var("SELECT term_id FROM {$wpdb->terms} WHERE name='Feadulta' LIMIT 1");
$changed=0;
foreach($rows as $r){
$cats=wp_get_post_categories($r->ID);
$new=array_values(array_diff($cats,$multi));
if(count($new)!==count($cats)){ if(!$new)$new=[$feadulta]; wp_set_post_categories($r->ID,$new); $changed++; }
}
echo "lecturas con Multimedia eliminada: $changed\n";