2013-08-20 4 views
0

내 Wordpress 앞 페이지에는 추천 기사 (상자 안에 스타일이 지정됨)와 최근 게시물 목록 (개별적으로 스타일이 지정됨)이 있습니다. 추천 게시물을 제외한 Wordpress 루프를 사용하여 최근 게시물을 표시하고 싶습니다. 특정 카테고리 나 태그를 제외하는 것은 쉽지만, 제 경우에는 맞춤 필드가있는 게시물을 제외하고 싶습니다. 추천 게시물에는 이름과 값이있는 사용자 정의 필드가 있습니다 : featured = yes.Wordpress 루프에서 추천 게시물 제외

플러그인을 사용하지 않고 어떻게이 작업을 수행 할 수 있습니까? http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters에 설명 된대로

답변

2

당신은 meta_query 매개 변수를 사용할 수 있습니다

뭔가 같은 :

$args = array(
    'post_type' => 'any', 
    'meta_query' => array(
     array(
      'key' => 'featured', 
      'value' => 'yes', 
      'compare' => 'NOT LIKE' 
     ) 
    ) 
); 

$query = new WP_Query($args); 
0
$args = array(
    'meta_query' => array(
     'relation' => 'AND', 
     array(
      'key' => 'featured', 
      'value' => 'yes', 
      'compare' => '=' 
     ), 
    )); 
$ids = array(); 
$query = new WP_Query($args); // fetching posts having featured = yes 
if ($query->have_posts()) { 
    while ($query->have_posts()) { 
     $query->the_post(); 
     $ids[] = $post->ID; // building array of post ids 
    } 
} 

$args = array('post__not_in' =>$ids); // excluding featured posts from loop 
query_posts($args); 

while (have_posts()) : the_post(); 
// rest of the code 
관련 문제