Created
June 6, 2017 17:03
-
-
Save tripflex/4dbd7d813f4b53b9dbb24564bd4e2217 to your computer and use it in GitHub Desktop.
WP Job Manager - Nearby Listings Button (shortcode and action outputs for Listify theme)
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 | |
add_shortcode( 'nearby_listings_btn', 'smyles_nearby_listings_btn' ); | |
function smyles_nearby_listings_btn( $atts = array(), $content = '' ){ | |
// Default output is blank | |
$output = ''; | |
$caption = __( 'Search Nearby Businesses' ); | |
// 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 | |
); | |
$output = "<a class=\"button button-secondary\" href=\"{$search_url}\" target=\"_blank\">{$caption}</a>"; | |
} | |
return $output; | |
} | |
// Comment out below (place // before add_action) to remove from showing next to "Write a Review" button | |
add_action( 'listify_single_job_listing_actions_after', 'smyles_nearby_listings_btn_after_author' ); | |
// Comment out below (place // before add_action) to remove from showing below Contact Business (bottom of author widget) | |
add_action( 'listify_widget_job_listing_author_after', 'smyles_nearby_listings_btn_after_author' ); | |
function smyles_nearby_listings_btn_after_author(){ | |
echo smyles_nearby_listings_btn(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment