2016-04-12 23 views
0

Bunun açıklanmasının en iyi yolu olduğundan emin değilsiniz, fakat burada neler olup bittiğine dair eminim (ve bunun kesinlikle makul bir şey olması gerektiğinden emin değilim. Nereye bakmalı):wordpress php loop - arşiv sonuçlarla aynı sayıda döngü yapıyor

İstemcinin 10 ofisi var, bu yüzden iş ilanları için bir yer belirtmek üzere özel bir yazı tipi ile Gelişmiş Özel Alanlar eklentisini kullanıyorum. Kodum çalışıyor gibi görünüyor (yani, uygun işleri konumla çekiyor), ancak sonuç olarak makalesinin etiketini aynı sayıda döndürüyor. Orada 3 tane işim var, bu yüzden 3 kez sonuç kümesini tamamlıyor. Ben bakmak için nereye emin değilim sanırım

<?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(). ?> 

(bu kudretini fark: Ben birini silin ve 2 aşağı düşerse ben gelişmiş özel aşağıdaki örnek kullandı vb iki kez döngüler web alanları bir php sorusu yerine bir eklenti sorusu) ve size sağlayabildiğiniz her yönüyle takdir edersiniz. Burada belirtildiği gibi, http://www.knrlegal.com/jobs/

cevap

0

Sen yazılan verileri değil, sorgu sıfırlamak gerekir: Class Reference/WP Query, "Birden Döngüler" bölümünde

Burada rahatsız edici sayfayı görebilirsiniz.

 <?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; ?>