wordpress php循环-存档循环次数与结果相同

wordpress php循环-存档循环次数与结果相同,php,custom-post-type,advanced-custom-fields,Php,Custom Post Type,Advanced Custom Fields,不确定这是否是描述它的最佳方式,但下面是正在发生的事情(我相信这一定是一件相当简单的事情,只是不确定去哪里看): 客户端有10个办公室,所以我使用带有自定义帖子类型的高级自定义字段插件来指定职位帖子的位置。我的代码似乎正常工作(即,它按位置拉取适当的作业),但它循环文章标记的次数与结果相同。我在那里有3个工作,所以它会循环整个结果集3次。如果我删除一个字段并下拉到2,它将循环两次,以此类推。我使用了高级自定义字段网站上的以下示例: <?php // args $args = array(

不确定这是否是描述它的最佳方式,但下面是正在发生的事情(我相信这一定是一件相当简单的事情,只是不确定去哪里看):

客户端有10个办公室,所以我使用带有自定义帖子类型的高级自定义字段插件来指定职位帖子的位置。我的代码似乎正常工作(即,它按位置拉取适当的作业),但它循环文章标记的次数与结果相同。我在那里有3个工作,所以它会循环整个结果集3次。如果我删除一个字段并下拉到2,它将循环两次,以此类推。我使用了高级自定义字段网站上的以下示例:

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

阿克伦办事处
我想我不知道该去哪里找(我意识到这可能是一个插件问题,而不是php问题),如果你们能提供任何指导,我将不胜感激


您可以在此处看到有问题的页面:

您应该重置post数据,而不是查询,如下所述: ,在“多个循环”部分


阿克伦办事处
        <?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; ?>