2015-05-19 61 views
1

我一直在嘗試很長時間來檢索post_title,post_content和功能圖像鏈接的基於特定類別,從wordpress數據庫的所有帖子。 (我會做一個JSON解析來填充功能的IMG和文章標題的Android列表視圖)MySql查詢檢索wordpress數據庫post_title,內容,特色圖像鏈接

我有一個查詢:

SELECT 
    p1.post_title,p1.post_content, 
    wm2.meta_value 
FROM 
    wp_posts p1 
LEFT JOIN 
    wp_postmeta wm1 
    ON (
     wm1.post_id = p1.id 
     AND wm1.meta_value IS NOT NULL 
     AND wm1.meta_key = "_thumbnail_id" 
    ) 
LEFT JOIN 
    wp_postmeta wm2 
    ON (
     wm1.meta_value = wm2.post_id 
     AND wm2.meta_key = "_wp_attached_file" 
     AND wm2.meta_value IS NOT NULL 
    ) 
WHERE 
    p1.post_status="publish" 
    AND p1.post_type="post" 
ORDER BY 
    p1.post_date DESC 

這工作得很好,但它沒有讓我根據一個特定類別的結果。

是否有人可以幫助我獲得基於特定類別

例如,對於所有帖子精選圖片:讓我們說wp_term_taxonomy.term_id = 48

請幫助!

回答

1

試試這個

SELECT p1.*, wm2.meta_value 
FROM wp_posts p1 
LEFT JOIN wp_postmeta wm1 ON (
    wm1.post_id = p1.id 
    AND wm1.meta_value IS NOT NULL 
    AND wm1.meta_key = '_thumbnail_id' 
) 
LEFT JOIN 
wp_postmeta wm2 
ON (
    wm1.meta_value = wm2.post_id 
    AND wm2.meta_key = '_wp_attached_file' 
    AND wm2.meta_value IS NOT NULL 
) 
LEFT JOIN 
wp_term_relationships wtr 
ON (
    object_id=p1.id 
) 
WHERE 
p1.post_status='publish' 
AND p1.post_type='post' 
AND `term_taxonomy_id`=? 
ORDER BY p1.post_date DESC 
LIMIT 0,10 
+0

我想類似的東西,並得到它的工作。無論如何,非常感謝! – Arin