طلب مني منذ فترة نقل محتوى قاعدة بيانات ووردبريس إلى قاعدة بيانات أخرى.. هذه هي الاستعلامات التي تأتي بالوسوم والتصنيفات والبوستات،، حيث تستطيعون إستخدام النتائج لتضموها مرة أخرى إلى قاعدة بيانات مخصصة..

وأحببت أن أشاركها لتعم الفائدة على الجميع..

لا تنسو أن تستبدلو البادئة للجداول في قاعدة البيانات لوورد بريس prefix

--only published

SELECT ID,post_date,post_title, post_content, post_excerpt, comment_status FROM prefix_posts WHERE post_status LIKE 'publish' AND post_type LIKE 'post'

--Picture of posts

SELECT guid FROM prefix_posts WHERE post_type LIKE 'attachment' AND post_mime_type LIKE '%image/%'

--The Relation of post-picture

SELECT t2.post_id, t2.meta_value FROM prefix_posts AS t1 JOIN prefix_postmeta AS t2 ON t1.ID = t2.post_id WHERE t1.post_status LIKE 'publish' AND t1.post_type LIKE 'post' AND t2.meta_key = '_thumbnail_id'

--The categories

SELECT t1.*, t2.* FROM prefix_terms as t1 JOIN prefix_term_taxonomy as t2 ON t1.term_id = t2.term_id WHERE t2.taxonomy = 'category' and t2.count >0

-- The tags

SELECT t1.*, t2.* FROM prefix_terms as t1 JOIN prefix_term_taxonomy as t2 ON t1.term_id = t2.term_id WHERE t2.taxonomy = 'post_tag' and t2.count >0

-- The tags or category of one POST

SELECT t1.ID, t1.post_title , t4.name, t4.term_id, t3.taxonomy FROM prefix_posts as t1 Right JOIN prefix_term_relationships as t2 on t2.object_id = t1.ID Right JOIN prefix_term_taxonomy as t3 on t3.term_taxonomy_id = t2.term_taxonomy_id Right JOIN prefix_terms as t4 ON t4.term_id = t3.term_id WHERE t1.ID = 41

-- The category of one POST

SELECT t1.ID, t1.post_title , t4.name, t4.term_id, t3.taxonomy FROM prefix_posts as t1 Right JOIN prefix_term_relationships as t2 on t2.object_id = t1.ID Right JOIN prefix_term_taxonomy as t3 on t3.term_taxonomy_id = t2.term_taxonomy_id Right JOIN prefix_terms as t4 ON t4.term_id = t3.term_id WHERE t1.ID = 41 AND t3.taxonomy = 'category'

-- The tags of one POST

SELECT t1.ID, t1.post_title , t4.name, t4.term_id, t3.taxonomy FROM prefix_posts as t1 Right JOIN prefix_term_relationships as t2 on t2.object_id = t1.ID Right JOIN prefix_term_taxonomy as t3 on t3.term_taxonomy_id = t2.term_taxonomy_id Right JOIN prefix_terms as t4 ON t4.term_id = t3.term_id WHERE t1.ID = 41 AND t3.taxonomy = 'post_tag'