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.
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();
}