Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created January 4, 2020 00:10
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/ff6030dde241509851a882d05f0472ed to your computer and use it in GitHub Desktop.
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)
<?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>
";
}
@tripflex
Copy link
Author

tripflex commented Jan 4, 2020

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, the job_address for actual address, job_city for actual city, and job_state for actual state. These fields can be dropdown, or text fields (can NOT be taxonomies)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment