2012-06-16 74 views
1

WHERE子句針對某一特定不同的分類,我試圖讓與特定分類的職位。在這種情況下,假設我是搜索與價值「兒子」的分類「電視」後,我想不出要查詢的表,因爲似乎沒有成爲電視一個明確的標識。電視的每個實例分配一個新的term_id和term_taxonomy_id。MySQL查詢表

我在我需要加入該表,並在其價值觀有點混亂。

請能有人給我一些建議,因爲我覺得我已經被拉從我的禿頭剩餘的頭髮。謝謝。我的查詢和DB值低於和DB圖如下,

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID, 
     MIN(wp_offers.price) 
FROM  wp_posts 
INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) 
LEFT JOIN wp_offers    ON (wp_posts.ID = wp_offers.post_id) 
WHERE DATE(wp_offers.offer_date) = '2012-05-18' 
    AND() # **********the query goes here********** 
    AND wp_term_relationships.term_taxonomy_id IN (8,9) 
    AND wp_posts.post_type = 'offer' 
    AND wp_posts.post_status = 'publish' 
GROUP BY wp_posts.ID 
ORDER BY wp_posts.post_title ASC 
LIMIT 0, 15 

**wp_term_relationships** 

object_id  term_taxonomy_id   term_order 
10   3    0 
10   4    0 
10   5    0 
21   3    0 


**wp_term_taxonomy** 

term_taxonomy_id  term_id  taxonomy  description  parent count 
3     3   television     0  2 
4     4   television     0  1 
5     5   television     0  1 


**wp_terms** 

term_id   name  slug  term_group 
3    SON  SON  0 
4    SAM  SAM  0 
5    TOS  TOS  0 

enter image description here

回答

0

如果你想在頁面上顯示他們,你可以只使用

$query = new WP_Query(array('television' => 'SON')); 

Wordpress Codex

0
$query = new WP_Query(array('television' => 'SON')); 

OR

$args = array(
'tax_query' => array(
    array(
     'taxonomy' => 'television', 
     'field' => 'slug', 
     'terms' => 'SON' 
     ) 
    ) 
); 
$query = new WP_Query($args); 

Reference.