Last active
December 6, 2024 21:17
-
-
Save nikitasinelnikov/1f50cc41a745409aef8fff074e7d661c to your computer and use it in GitHub Desktop.
JobBoardWP: Custom fields on job posting form
This file contains hidden or 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
// Please replace 'my-custom-key' to your real meta key | |
// there can be more than 1 custom meta fields | |
function jb_custom_job_data( $data, $job_id ) { | |
$data['my-custom-key'] = get_post_meta( $job_id, 'my-custom-key', true ); | |
return $data; | |
} | |
add_filter( 'jb-job-raw-data', 'jb_custom_job_data', 10, 2 ); | |
function my_custom_validation( $posting_form, $user_id ) { | |
if ( empty( $_POST['my-custom-key'] ) ) { | |
$posting_form->add_error( 'my-custom-key', __( 'My custom field\'s label name cannot be empty', 'jobboardwp' ) ); | |
} | |
} | |
add_action( 'jb-job-submission-validation', 'my_custom_validation', 10, 2 ); | |
function my_custom_job_data_submitted( $job_data, $posting_form ) { | |
$job_data['meta_input']['my-custom-key'] = sanitize_text_field( $_POST['my-custom-key'] ); | |
return $job_data; | |
} | |
add_filter( 'jb_job_submitted_data', 'my_custom_job_data_submitted', 10, 2 ); | |
// If you extends company data | |
function my_custom_user_company_data( $company_data, $user_id ) { | |
$company_data['my_custom_key'] = get_user_meta( $user_id, 'jb_company_my_custom_key', true ); | |
return $company_data; | |
} | |
add_filter( 'jb-user-company-data', 'my_custom_user_company_data', 10, 2 ); | |
function my_custom_job_company_data( $company_data, $job_id ) { | |
$company_data['my_custom_key'] = get_post_meta( $job_id, 'jb-company-my_custom_key', true ); | |
return $company_data; | |
} | |
add_filter( 'jb-job-company-data', 'my_custom_job_company_data', 10, 2 ); | |
function my_custom_save_user_company_data( $data, $job_id ) { | |
$data['my_custom_key'] = sanitize_text_field( $_POST['company_my_custom_key'] ); | |
return $data; | |
} | |
add_filter( 'jb-save-job-user-company-data', 'my_custom_save_user_company_data', 10, 2 ); |
This file contains hidden or 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
/*line:41*/ | |
$job_my_custom_key = '{default_value}'; // basic default value which we may show on the form after first loading | |
$company_my_custom_key = '{default_value}'; // basic default value which we may show on the form after first loading | |
/*line:61*/ | |
if ( is_user_logged_in() ) { | |
$c_data = JB()->common()->user()->get_company_data(); | |
/*...some other data above...*/ | |
$company_my_custom_key = $c_data['my_custom_key']; | |
/*...some other data below...*/ | |
} | |
/*line:71*/ | |
if ( $edit ) { | |
$data = JB()->common()->job()->get_raw_data( $jb_job_submission['job']->ID ); // getting job's data on edit | |
/*...some other data above...*/ | |
$job_my_custom_key = $data['my-custom-key']; | |
/*...some other data below...*/ | |
} | |
/*line:223*/ | |
$sections['job-details']['fields'][] = [ | |
'type' => 'text', // can be 'hidden', 'media', 'text', 'location_autocomplete', 'password', 'select', 'conditional_radio', 'wp_editor | |
'label' => __( 'My custom key\'s label', 'jobboardwp' ), | |
'id' => 'my-custom-key', | |
'required' => true, // set true if required | |
'value' => $job_my_custom_key, | |
]; | |
$sections['company-details']['fields'][] = [ | |
'type' => 'text', // can be 'hidden', 'media', 'text', 'location_autocomplete', 'password', 'select', 'conditional_radio', 'wp_editor | |
'label' => __( 'Company My custom key\'s label', 'jobboardwp' ), | |
'id' => 'company_my_custom_key', | |
'required' => true, // set true if required | |
'value' => $company_my_custom_key, | |
]; |
I added this code in and nothing happens. I changed my-custom-key to whatever I wanted. Nothing shows up?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @L422Y
You may find the base file in
wp-content/plugins/jobboardwp/templates/job-submission.php
path. Then copy it to your theme/child-theme and then add necessary customizations.Please take a look at this doc for more details and templates mapping. https://docs.jobboardwp.com/article/1570-templates-structure