douman6679 2017-10-04 13:34
浏览 39
已采纳

使用WP作业管理器中的“get_job_listings”函数按位置查询作业列表

I am using the WP Job Manager for WordPress and currently have the following code in my theme that pulls jobs and displays them on my homepage.

<?php

        $jobs = get_job_listings( array(
            'posts_per_page'    => 3,
            'orderby'           => 'date',
            'order'             => 'DESC'
        ) );

if (  $jobs->have_posts() ) { ?>

      <ul> 
        <div class="container">
            <?php while ( $jobs->have_posts() ) : $jobs->the_post(); ?>
                <?php get_job_manager_template_part( 'content-widget', 'job_listing' ); ?>
            <?php endwhile; ?>
        </div>
      </ul> <?php

    //* Restore original Post Data
    wp_reset_postdata();

}

?>

It's simple and it works but what I would like to do is display only the jobs from a specific country.

I'd like to list all of my jobs from the UK on one page. All of the jobs from Germany on another and then show all jobs that are NOT based in the UK or Germany on a third page.

  • 写回答

1条回答 默认 最新

  • dongyuanguang3893 2017-10-04 15:09
    关注

    It looks like you can actually pass search_location into your get_job_listings query. So for Germany, you'd run something this:

            $jobs = get_job_listings( array(
            'posts_per_page'    => 3,
            'orderby'           => 'date',
            'order'             => 'DESC',
            'search_location'   => 'Germany'
        ) );
    

    To remove countries displayed per your comment, I had trouble excluding them from the query, so I can only tell you how to not display them... In other words, there's probably a more efficient way to do this, but I couldn't get it to work. So this will probably work for your needs:

     $jobs = get_job_listings( array(
      'posts_per_page'    => -1,
      'orderby'           => 'date',
      'order'             => 'DESC',
    
     ) );
    
     if (  $jobs->have_posts() ) { ?>
    
     <ul>
     <div class="container">
       <?php while ( $jobs->have_posts() ) : $jobs->the_post(); ?>
         <?php $country = get_post_meta(get_the_ID(), 'geolocation_country_short', true); ?>
        <?php
          if ($country == 'DE' || $country == 'NO'){
            continue;
          }else {
            get_job_manager_template_part( 'content-widget', 'job_listing' );
          }
       ?>
     <?php endwhile; ?>
     </div>
     </ul> <?php
    
    
     wp_reset_postdata();
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?