EUCOOKIELAW_BANNER_TITLE

  • I think that

    Making the Web is like playing a game. Standard, Accessibility and Usability are only few rules.
    No game is awesome if you don't follow the rules.

    International Webmasters Association

  • Subscribe to my blog via email

    Insert here your e-mail address and you will receive a message when a new post will come.

Riportare tutti gli articoli di una categoria in bozza

La relazione tra articoli e categorie è mantenuta dalla tabella wp_term_relationships. Questa è una tabella per la definizione di una relazione molti a molti tra le tabelle wp_term_taxonomy e wp_posts.

  • object_id è la chiave d’accesso alla tabella wp_posts,
  • term_taxonomy_id è l’identificativo  d’accesso alla tabella wp_term_taxonomy.
select
  *
from
  wp_term_relationships
where
  term_taxonomy_id in (
    select
     taxonomy.term_taxonomy_id
    from
     wp_terms terms left join wp_term_taxonomy taxonomy on terms.term_id = taxonomy.term_id
    where
     taxonomy.taxonomy = 'category' and
     terms.name = 'Mia Categoria');

oppure per proporla in una forma più corretta:

select  
   relationships.object_id
from
   wp_terms terms left join  
   wp_term_taxonomy taxonomy on terms.term_id = taxonomy.term_id left join  
   wp_term_relationships relationships on taxonomy.term_taxonomy_id = relationships.term_taxonomy_id  
where
   taxonomy.taxonomy = 'category' and
   terms.name = 'Mia categoria';

Quindi abbiamo tutti gli identificativi dei post legati ad una precisa categoria.

Ne viene di conseguenza la query per aggiornare lo stato degli articoli in bozza (‘draft’):

update wp_posts set post_status = 'draft' where ID in (
  select  
     relationships.object_id
  from
     wp_terms terms left join  
     wp_term_taxonomy taxonomy on terms.term_id = taxonomy.term_id left join  
     wp_term_relationships relationships on taxonomy.term_taxonomy_id = relationships.term_taxonomy_id 
  where
     taxonomy.taxonomy = 'category' and
     terms.name = 'Mia categoria');