Created
May 24, 2017 15:55
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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