2014-06-10 3 views
0

특정 사용자 정의 필드가 포함 된 모든 WordPress 게시물을 표시하는 페이지를 만들려고합니다. 이 작업을 수행하는 가장 좋은 방법은 "사용자 정의 페이지 템플리트"를 작성하고 새로운 WP_query를 사용하여 해당 게시물을 나열하는 것입니다. 새 "페이지"를 만들고 새 WP_query에 새 "페이지 템플릿"을 적용했지만 페이지에 게시물이 표시되지 않았습니다. 왜이 사용자 정의 페이지 템플릿이 문제의 게시물을 올바르게 나열하지 않는지 내게 말할 수 있습니까? 어떤 도움을 많이 주시면 감사하겠습니다! 나는 $args 변수에 포스트 유형을 지정하는 경우사용자 정의 필드로 Wordpress 게시물을 표시하는 방법

<?php 

/** 

* Template Name: Recommended Incentives 


* 

* @package WordPress 

* @subpackage Twenty_Fourteen 

* @since Twenty Fourteen 1.0 

*/ 



get_header(); ?> 



<div id="main-content" class="main-content"> 







    <div id="primary" class="content-area"> 

     <div id="content" class="site-content" role="main"> 


      <?php 

// args 
$args = array(

    'meta_key' => 'Incentive ID', 
    'meta_value' => '20' 
); 

// get results 
$the_query = new WP_Query($args); 

// The Loop 
?> 
<?php if($the_query->have_posts()): ?> 
    <ul> 
    <?php while ($the_query->have_posts()) : $the_query->the_post(); ?> 
     <li> 
      <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 
     </li> 
    <?php endwhile; ?> 
    </ul> 
<?php endif; ?> 

<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?> 


     </div><!-- #content --> 

    </div><!-- #primary --> 

</div><!-- #main-content --> 



<?php 

get_sidebar(); 

get_footer(); 
+0

나는'$ args' 변수에 게시물 유형을 지정해야한다고 생각합니다. 주요 "posts"섹션에서 쿼리를 시도하는 경우''post_type '=>'post ''를 사용하는 것이 좋습니다. – AndyWarren

답변

0

감사 앤디, 내 코드했다. 내가 사용하는 코드는

'meta_key' => 'Incentive ID', 
    'meta_value' => array(20,21), 
    'orderby' => 'meta_value_num', 
    'order' => 'ASC', 
    'post_type' => 'incentives'