2011-02-06 85 views
0

只有在滿足使用自定義字段的三個條件時,我纔會讓wordpress發佈最新帖子。首先河必須是'科羅拉多',區域必須是'區域4'並且位置必須是'soundbite 5'。這甚至有可能做到嗎?如果自定義字段爲true,則顯示最新帖子

到目前爲止的代碼:

<?php $querystr = " 
     SELECT wposts.* 
     FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta 
     WHERE wposts.ID = wpostmeta.post_id 
     AND wpostmeta.meta_key = 'select_river' 
     AND wpostmeta.meta_value = 'Colorado' 
     AND wpostmeta.meta_key = 'select_area' 
     AND wpostmeta.meta_value = 'Area 4' 
     AND wpostmeta.meta_key = 'select_soundbite_position' 
     AND wpostmeta.meta_value = 'soundbite 5' 
     AND wposts.post_status = 'publish' 
     AND wposts.post_type = 'post' 
     ORDER BY wposts.post_date DESC 
     "; 

    $pageposts = $wpdb->get_results($querystr, OBJECT); 

     if ($pageposts): 
     foreach ($pageposts as $post): 
     setup_postdata($post); ?> 

     <p>Test</p> 

     <?php endforeach; ?> 
    <?php endif; ?> 

它不工作,我不知道爲什麼......以及我的PHP的理解是缺乏

回答

0

什麼有關:

<?php 
$querystr = " 
     SELECT wposts.* 
     FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta, $wpdb->postmeta wpostmeta2, $wpdb->postmeta wpostmeta3 
     WHERE wposts.ID = wpostmeta.post_id 
     AND wpostmeta.meta_key = 'select_river' 
     AND wpostmeta.meta_value = 'Colorado' 
     AND wpostmeta2.meta_key = 'select_area' 
     AND wpostmeta2.meta_value = 'Area 4' 
     AND wpostmeta3.meta_key = 'select_soundbite_position' 
     AND wpostmeta3.meta_value = 'soundbite 5' 
     AND wposts.post_status = 'publish' 
     AND wposts.post_type = 'post' 
     ORDER BY wposts.post_date DESC 
     "; 
?> 
相關問題