2013-03-07 99 views
0

我想從循環中排除過濾器(slug)。我正在研究排除,並在代碼中的各個地方嘗試過。通常我會打破這個頁面。這是代碼,我試圖改變排除slug 20.它是一個名爲'美國'的過濾器。我試圖排除在陣列的開始,沒有工作;然後,我嘗試了foreach($ catz as $ cat)部分。我試過這個'exclude = 20 & title_li ='。我嘗試了貓= -20和其他各種組合。任何幫助將非常感激。wp如何從自定義查詢中排除過濾器

// The Custom Query 
$args = array(
'post_type'   => 'portfolio', 
'posts_per_page' => $counter_folio, 
'paged'    => $paged, 
'order'    => 'DESC' 

); 
query_posts($args); 
while(have_posts()) : the_post(); 
$color = substr(get_option('dcb_dynamic_color'), 1); 
// Get the original thumbnail of the post 
$src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), false, ''); 
$excerpt = get_the_excerpt(); 
// Get the custom fields 
$vimeo = get_post_meta($post->ID, "vimeo", true); 
$youtube = get_post_meta($post->ID, "youtube", true); 
// Get the filter > Category of item 
$catz = wp_get_object_terms($post->ID,'filters'); 
foreach($catz as $cat){ 
    $currcat = $cat->slug; 
    $catname = $cat->name; 
    break; 
} 
$counter++; 
?> 
+0

排除它,請不要使用'query_posts'是壞的查詢數據,它的問題和不可靠的。使用'WP_Query'來代替,你將會對你的數據有更多的控制並且安心:) – 2013-03-07 13:01:10

回答

0

如果要篩選與ID後20簡單用下面的代碼

// The Custom Query 
    $args = array(
    'post_type'   => 'portfolio', 
    'posts_per_page' => $counter_folio, 
    'paged'    => $paged, 
    'order'    => 'DESC' 

    ); 
    query_posts($args); 
    while(have_posts()) : the_post(); 
    $color = substr(get_option('dcb_dynamic_color'), 1); 
    // Get the original thumbnail of the post 
    $src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), false, ''); 
    $excerpt = get_the_excerpt(); 
    // Get the custom fields 
    $vimeo = get_post_meta($post->ID, "vimeo", true); 
    $youtube = get_post_meta($post->ID, "youtube", true); 
    // Get the filter > Category of item 
    $catz = wp_get_object_terms($post->ID,'filters'); 
    foreach($catz as $cat){ 
    if($cat->slug != 'american') 
    { 
     $currcat = $cat->slug; 
     $catname = $cat->name; 
     break; 
    } 
    } 
    $counter++; 
+0

謝謝。這是我一直在嘗試排除的地方。我把你的代碼放在了位置上,但它不起作用。然而,它也沒有破壞頁面,這是我的代碼不斷做的。 – user2141887 2013-03-07 16:09:17

+0

我認爲它必須是:如果一個職位有這個slu exclude排除它。然後排除名稱。 – user2141887 2013-03-07 16:26:00

+0

好吧,我添加了$ exclude = get_cat_ID('american');而不是如果..,它的工作,但現在我仍然有title_li來處理。 – user2141887 2013-03-07 22:08:19