2015-05-24 52 views
0

我正在開發我的第一個WordPress主題,我有的第一個循環只輸出1個項目:鏈接到主頁(不是我試圖在數組中傳遞的任何參數) 。get_posts只顯示一個鏈接到主頁

這裏的PHP和HTML:

<div class="services_list">   
    <?php 
     $args = array(
      'posts_per_page'=> 999, 
      'orderby'  => 'menu_order', 
      'order'   => 'ASC', 
      'post_type'  => 'service', 
      'meta_key'  => 'featured', 
      'meta_value' => '1' 
     ); 
    // The Query 
    get_posts($args); 
    // The Loop 
    while (have_posts()) : the_post(); ?> 
     <div class="service_item"> 
      <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="service_top_link"> 
       <div class="service_image"><?php the_post_thumbnail(array(120,120)); ?></div> 
      </a> 
      <h3 class="service_title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3> 
      <div class="service_excerpt"><?php the_excerpt(); ?></div> 
      <a href="<?php the_permalink(); ?>" title="Learn More" class="learn_more" role="button">Learn More</a> 
     </div><!-- .service_item --> 
    <?php endwhile; 
     // Reset Query 
     wp_reset_query(); 
    ?> 
</div><!-- .services_list --> 

我道歉,如果這個問題已經回答了,但我似乎無法找到它的任何東西。

+1

對於二級循環,您應該使用['WP_Query'](https://codex.wordpress.org/Class_Reference/WP_Query)。有關何時使用什麼的解釋,請參閱http://wordpress.stackexchange.com/a/1755/38742。 – Peter

回答

0

工作!謝謝。我從get_posts切換到使用WP_query,並且遇到同樣的問題。原來問題實際上是用元值,而不是查詢本身。

相關問題