How to add the extra field to job post
Sometimes we need to add more fields to the job posting form. This is step by step for how to add more fields to the job posting form via child theme.
Step 1: Add new extra field to job posting form on both file wp-content\themes\injob-child\iwj\dashboard\new-job\form.php
and wp-content\themes\injob-child\iwj\dashboard\edit-job.php
iwj_field_text('new_job_field', __('New custom field *', 'iwjob'), true, $post_id, null, '', '', __('Enter the value', 'iwjob'));
Step 2: Process for save job custom field on job update function.
add_action('iwj_update_job', 'update_job_custom_field'); add_action('iwj_add_new_job', 'update_job_custom_field'); function update_job_custom_field($post_id){ $custom_field = sanitize_text_field($_POST['new_job_field']); update_post_meta($post_id, 'new_job_field', $custom_field ); }
Step 3: Add new extra field to job posting in backend via filter iwj_admin_job_fields
on file functions.php
add_filter('iwj_admin_job_fields', function($fields) { $fields['general']['fields'][] = array( 'name' => __('New custom field', 'injob'), 'id' => 'new_job_field', 'type' => 'text', 'required' => true, ); return $fields; }
Step 4: Process for admin save job detail.
add_action('iwj_admin_save_job', function($pid) { $custom_field = sanitize_text_field($_POST['new_job_field']); update_post_meta($pid, 'new_job_field', $custom_field ); });
Step 5: Show custom field data on job detail page
Copy job detail template from plugin on wp-content/plugins/iwjob/templates/parts/job-details/
to wp-content/themes/injob-child/iwj/parts/job-details/
Then you can use this code to show your custom field value
$new_field_val = get_post_meta($job->get_id(), 'new_job_field', true); echo esc_attr($new_field_val);
All done!
2 comments
It is not clear whether step 1 and step 2 goes into both form.php and edit-job.php or only one of them
I update the post to clarify this, you need to add a custom field to both files