2013-03-07 97 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