2012-08-02 4 views
2

좋은 아침, 나는 사용자 정의 포스트 유형 만든맞춤 게시물 유형의 추천 게시물 만 표시하는 방법은 무엇입니까?

- 제품 - featured_product - - 고급 사용자 정의 필드 플러그인을 사용하여 내가 해야하고 사용자 정의 포스트 유형에 대한 사용자 정의 필드를 만들었습니다. 사용자 정의 필드를 만들 때 True/False 필드 유형을 사용하여 작성했습니다.

featured_product 확인란 이 선택된 제품 게시물 만 표시하려고합니다.

이 내 현재 코드입니다 :

<?php query_posts(array(
'posts_per_page' => 3, 
'post_type' => 'products', 
'orderby' => 'post_date', 
'paged' => $paged 
) 
); ?> 

<?php if (have_posts()) while (have_posts()) : the_post(); ?> 

<?php if(get_field('featured_product')){ ?> 

<div id="post-<?php the_ID(); ?>" class="cpt"> 
<h2><?php the_title(); ?></h2> 
<?php 
if (has_post_thumbnail()) { 
    the_post_thumbnail('excerpt'); 
} 
?> 
<?php the_excerpt(); ?> 
<ul class="prod_detail"> 
<li><a href="<?php the_field('product_detail_page'); ?>">Learn More</a></li> 
<li><a href="<?php the_field('purchase_link'); ?>">Place Order</a></li> 
</ul> 
</div> 

<?php } ?> 

<?php endwhile; ?> 

<?php wp_reset_query(); ?> 

문제는 단지 하나 개의 게시물을 반환하는 것입니다 -하지만 난 기능을 갖춘 것으로 확인 3 개 게시물이 있습니다.

내가 뭘 잘못하고 있니?

감사합니다.

답변

8

나는

<?php query_posts(array(
'posts_per_page' => 3, 
'post_type' => 'products', 
'orderby' => 'post_date', 
'meta_key' => 'featured_product', // the name of the custom field 
'meta_compare' => '=', // the comparison (e.g. equals, does not equal, etc...) 
'meta_value' => 1, // the value to which the custom field is compared. In my case, 'featured_product' was a true/false checkbox. If you had a custom field called 'color' and wanted to show only those blue items, then the meta_value would be 'blue' 
'paged' => $paged 
) 
); ?> 

<?php if (have_posts()) while (have_posts()) : the_post(); ?> 

<div id="post-<?php the_ID(); ?>" class="cpt"> 
<h2><?php the_title(); ?></h2> 
<?php 
if (has_post_thumbnail()) { 
    the_post_thumbnail('excerpt'); 
} 
?> 
<?php the_excerpt(); ?> 
<ul class="prod_detail"> 
<li><a href="<?php the_field('product_detail_page'); ?>" target="_blank">Learn More</a></li> 
<li><a href="<?php the_field('purchase_link'); ?>" target="blank">Place Order</a></li> 
</ul> 
</div> 

<?php endwhile; ?> 

<?php wp_reset_query(); ?> 
그것을 밖으로 :) 생각
관련 문제