Plugin Contributor
Davor
(@davoraltman)
Hi there,
Please use the filter submit_job_form_fields
to add a new field. For WP Admin area, please use job_manager_job_listing_data_fields
. For details on this, check out our tutorial here:
https://wpjobmanager.com/document/editing-job-submission-fields/
Also, I see that you missed an e in $fields['_job_exprience']
in the first snippet.
Let me know how it goes.
Thanks,
Davor
Thread Starter
kivo7
(@kivo7)
Hi, Davor
Actually I read your tutorial several times and even made some fields with succes. But there were textarea fields, not selectboxes.
My full code is:
//** Add field "job_experience" to the frontend
add_filter( 'submit_job_form_fields', 'frontend_add_experience_field' );
function frontend_add_experience_field( $fields ) {
$fields['job']['job_experience'] = array(
'label' => __( 'Experience' ),
'type' => 'select',
'required' => false,
'priority' => 8,
'options' => array(
'option1' => 'no experience', // 'value'=>'label'
'option2' => '1 year',
'option3' => '2 years',
'option4' => '5 years' )
);
return $fields;
}
//** Add field "job_experience" to admin
add_filter( 'job_manager_job_listing_data_fields', 'admin_add_experience_field' );
function admin_add_experience_field( $fields ) {
$fields['_job_experience'] = array(
'label' => __( 'Experience' ),
'type' => 'select',
'required' => false,
'priority' => 8,
'options' => array(
'option1' => 'no experience', // 'value'=>'label'
'option2' => '1 year',
'option3' => '2 years',
'option4' => '5 years' )
);
return $fields;
}
//** Display "job_experience" on the single job page
add_action( 'single_job_listing_meta_end', 'display_job_experience_data' );
function display_job_experience_data() {
global $post;
$experience = get_post_meta( $post->ID, '_job_experience', true );
if ( $experience ) {
echo '<li>' . __( 'Experience: ' ) . esc_html( $experience ) . '</li>';
}
}
Please let me know how to display the label of my filed on the single job page. Now I have only the value: http://prntscr.com/ggx9a2 . But I need to display not “option1”, but “no experience”.
Hi there,
Thanks for your screenshots and the code.
That’s reasonable because you’re saving option1
in your database. The following code is pulling that value only.
$experience = get_post_meta( $post->ID, '_job_experience', true );
To resolve this, you can do something like this.
Change the code
//** Display "job_experience" on the single job page
add_action( 'single_job_listing_meta_end', 'display_job_experience_data' );
function display_job_experience_data() {
global $post;
$experience = get_post_meta( $post->ID, '_job_experience', true );
if ( $experience ) {
echo '<li>' . __( 'Experience: ' ) . esc_html( $experience ) . '</li>';
}
}
to
//** Display "job_experience" on the single job page
add_action( 'single_job_listing_meta_end', 'display_job_experience_data' );
function display_job_experience_data() {
global $post;
$value_label = array(
'option1' => 'no experience', // 'value'=>'label'
'option2' => '1 year',
'option3' => '2 years',
'option4' => '5 years' )
);
$experience_value = get_post_meta( $post->ID, '_job_experience', true );
$experience = $value_label[ 'experience_value' ]; // Get label
if ( $experience ) {
echo '<li>' . __( 'Experience: ' ) . esc_html( $experience ) . '</li>';
}
}
Please note that: this is just an example. You might handle your code in some cases like there is no value, etc. If not, your code might break somehow.
Cheers,