Created
January 4, 2020 00:10
-
-
Save tripflex/ff6030dde241509851a882d05f0472ed to your computer and use it in GitHub Desktop.
Set job_location field from other field values (to separate job_location into multiple fields)
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_action( 'submit_job_form_start', 'smyles_auto_set_job_location' ); | |
function smyles_auto_set_job_location() { | |
echo " | |
<script> | |
jQuery( function( $ ){ | |
function smyles_update_job_location(){ | |
var address = $('#job_address').val(); | |
var city = $('#job_city').val(); | |
var state = $('#job_state').val(); | |
var built_location = state; | |
if( city.length > 0 && address.length > 0 ){ | |
built_location = address + ' ' + city + ', ' + state; | |
} | |
$('#job_location').val( built_location ); | |
} | |
$('#job_address').change( smyles_update_job_location ); | |
$('#job_city').change( smyles_update_job_location ); | |
$('#job_state').change( smyles_update_job_location ); | |
setTimeout( smyles_update_job_location, 2000 ); | |
}); | |
</script> | |
"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For this to work you MUST change the
job_location
field to a hidden field type. You must also then add 3 additional fields as well, thejob_address
for actual address,job_city
for actual city, andjob_state
for actual state. These fields can be dropdown, or text fields (can NOT be taxonomies)