Mysql
 sql >> Database >  >> RDS >> Mysql

In che modo Wordpress collega i post alle categorie nel suo database?

Le relazioni del database di Wordpress sono disponibili nel diagramma del database .

Nel tuo caso particolare è:

wp_posts.ID
->wp_term_relationships.object_id
->wp_term_relationships.term_taxonomy_id
->wp_term_taxonomy.term_taxonomy_id
->wp_term_taxonomy.term_id
->wp_terms.term_id

Per eseguire query è necessario utilizzare un join SQL:

SELECT p.ID, t.term_id
FROM wp_posts p
LEFT JOIN wp_term_relationships rel ON rel.object_id = p.ID
LEFT JOIN wp_term_taxonomy tax ON tax.term_taxonomy_id = rel.term_taxonomy_id
LEFT JOIN wp_terms t ON t.term_id = tax.term_id

Ma va notato che il database di wordpress potrebbe cambiare in qualsiasi momento e dovresti usare i meccanismi forniti da Wordpress (come query_posts ) per filtrare i post dal database.