Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created May 24, 2017 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/e869079b918add721fec36adfa163a34 to your computer and use it in GitHub Desktop.
Save tripflex/e869079b918add721fec36adfa163a34 to your computer and use it in GitHub Desktop.
Example PHP code for WP Job Manager to build a custom link from Job Location to search for nearby Listings
<?php
// First let's get the permalink to the listings page
$jobs_list_page = job_manager_get_permalink( 'jobs' );
// Next we need to pull the value the user entered in the job_location field
$job_location = get_custom_field( 'job_location' );
// Then we get from post meta the value of `geolocated` which will be 1 when core WP Job Manager has geolocation data for this listing
$is_geolocated = get_post_meta( get_the_ID(), 'geolocated', true );
// Verify we have a valid job lists page, a value for job location, and the listing has been geolocated
// We check geolocated to make sure that the job_location value *should* be a valid address
if( ! empty( $jobs_list_page ) && ! empty( $job_location ) && ! empty( $is_geolocated ) ){
$search_url = add_query_arg(
array(
'search_location' => $job_location,
'use_search_radius' => 'on',
'search_radius' => '8'
),
$jobs_list_page
);
echo "<a class=\"some-custom-class\" href=\"{$search_url}\" target=\"_blank\">Find Nearby</a>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment