2013-03-07 2 views
0

루프에서 필터 (슬러그)를 제외하려고합니다. 나는 exclude를 연구하여 코드의 여러 위치에서 시도했다. 보통 나는 그 페이지를 깬다. 이 코드는 슬러그 20을 제외하기 위해 변경하려고 시도하고 있습니다. 'american'이라는 필터입니다. 나는 배열의 시작 부분에서 제외하려고했으나 작동하지 않았다. 그런 다음 foreach ($ catz $ cat) 섹션 다음에 시도했습니다. 나는 이것을 'exclude = 20 & title_li ='시도했다. 나는 cat = -20과 다양한 조합을 시도했다. 어떤 도움이라도 대단히 감사 할 것입니다. 당신이 ID로 게시물을 필터링하려면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'를 사용하면 데이터와 마음의 평화를보다 잘 제어 할 수 있습니다 :) –

답변

0

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

+0

나는 그것이 있어야한다라고 생각한다 : 만일 포스트가이 슬러그를 제외하면 그것을 제외해라. 그런 다음 이름을 제외하십시오. – user2141887

+0

음, $ exclude = get_cat_ID ('american')를 추가했습니다. if ... 대신에 .. 그리고 효과가 있었지만 지금은 여전히 ​​title_li를 다루어야합니다. – user2141887