This documentation shows how to add fields on the Job Submission fields from the frontend and then output them on a single job listing.
To add these fields we will use some PHP filter to which you can add it on the theme’s functions.php file, or even better, use a functionality plugin such as Code Snippets, and create a function to append a new field to the jobs section.
To add Salary and Hourly Rate fields in the Job submission page on your frontend, please inject this into your functions.php file:
function frontend_add_salary_field( $fields ) {
$fields['job']['salary_min'] = array(
'label' => esc_html__( 'Minimum salary', 'jobify' ) . $currency,
'type' => 'text',
'required' => false,
'placeholder' => esc_html__( 'e.g. 400','jobify' ),
'priority' => 9
);
$fields['job']['salary_max'] = array(
'label' => esc_html__( 'Maximum salary', 'jobify' ) . $currency,
'type' => 'text',
'required' => false,
'placeholder' => esc_html__( 'e.g. 700', 'jobify' ),
'priority' => 10
);
$fields['job']['hour_rate'] = array(
'label' => esc_html__( 'Hourly rate/h', 'jobify' ) . $currency,
'type' => 'text',
'required' => false,
'placeholder' => esc_html__( 'e.g. 20','jobify' ),
'priority' => 11
);
return $fields;
}
add_filter( 'submit_job_form_fields', 'frontend_add_salary_field' );
Next to display these fields within the single job listing post you can use these two filters:
add_action( 'single_job_listing_meta_end', 'display_job_salary_data');
//Then we write a function which gets the value of the meta and outputs it in list format:
function display_job_salary_data() {
global $post;
$salary_min = get_post_meta( $post->ID, '_salary_min', true );
if ( $salary_min ) {
echo '<li>' . __( 'Min Salary:' ) . ' $' . esc_html( $salary_min ) . '</li>';
}
$salary_max = get_post_meta( $post->ID, '_salary_max', true );
if ( $salary_max ) {
echo '<li>' . __( 'Max Salary:' ) . ' $' . esc_html( $salary_max ) . '</li>';
}
}
add_action( 'single_job_listing_meta_end', 'display_job_hourly_data');
function display_job_hourly_data() {
global $post;
$hourly_rate = get_post_meta( $post->ID, '_hour_rate', true );
if ( $hourly_rate ) {
echo '<li>' . __( 'Hourly rate/h:' ) . ' $' . esc_html( $hourly_rate ) . '</li>';
}
}