2016-04-12 8 views
0

これを説明する最善の方法はわかりませんが、ここには何が起こっているのですか(そして、これはかなり簡単なことですどこに見えるか):wordpress PHPループ - アーカイブは結果と同じ回数だけループしています

クライアントには10​​のオフィスがありますので、私はカスタムポスティングタイプのAdvanced Custom Fieldsプラグインを使って求人情報の場所を指定しています。コードが正常に動作しているようです(具体的には、場所によって適切なジョブが引き出されています)。の記事タグは結果と同じ回数だけループしています。私はそこに3つの仕事を持っているので、結果セット全体を3回ループします。私は私が見てどこか分からないと思います

<?php 
// args 
$args = array(
    'numberposts' => -1, 
    'post_type'  => 'jobs', 
    'meta_key'  => 'location', 
    'meta_value' => 'akron' 
); 

// query 
$the_query = new WP_Query($args); 

?> 
<?php if($the_query->have_posts()): ?> 
    <h3>Akron Office</h3> 
    <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(). ?> 

(私はこれかもしれないを実現:私は1つを削除し、2まで低下した場合、それは私が高度なカスタムから次の例を使用など、二回ループすると、ウェブサイトフィールドphpの質問ではなくプラグインの質問になります)、皆さんが提供できるあらゆる方向性に感謝します。あなたがここに問題のページを参照してくださいすることができます

http://www.knrlegal.com/jobs/

答えて

0

をここに述べたようにあなたは、ポストデータではなく、クエリをリセットする必要があります。 Class Reference/WP Query、「複数のループ」のセクションで。

 <?php 
    // args 
    $args = array(
     'numberposts' => -1, 
     'post_type'  => 'jobs', 
     'meta_key'  => 'location', 
     'meta_value' => 'akron' 
    ); 

    // query 
    $the_query = new WP_Query($args); 

    ?> 
    <?php if($the_query->have_posts()): ?> 
     <h3>Akron Office</h3> 
     <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 
    /* Restore original Post Data 
    * NB: Because we are using new WP_Query we aren't stomping on the 
    * original $wp_query and it does not need to be reset with 
    * wp_reset_query(). We just need to set the post data back up with 
    * wp_reset_postdata(). 
    */ 
    wp_reset_postdata(); 
    ?>  
    <?php endif; ?> 
関連する問題