Where are you hoping to display the fields? Assuming Remi’s plugin saves the meta for your jobs, could you not get it manually (get_post_meta) and output elsewhere?
There are snippets in this tutorial for outputting meta information https://wpjobmanager.com/document/tutorial-adding-a-salary-field-for-jobs/#section-4
Does that help?
Hey Mike,
Thanks for the fast response. With Remi’s plugin, I couldn’t manage to output the value with get_post_meta when the custom field type is a select list. I tried this;
<?php $myvalue = explode(",", get_post_meta( $post->ID, 'custom_field_slug', true ) ); print_r($myvalue); ?>
I’m i doing something wrong ? The get_post_meta is working fine however with text fields.
<?php echo get_post_meta( $post->ID, 'custom_field_slug', true ) ?>
Got another question for you, I use a custom function that filter some custom fields to change their priorities and it’s working fine. Is it possible to move a custom field to the “Company details” section on job submission ?
What does print_r(get_post_meta( $post->ID, ‘custom_field_slug’, true )); give you? See what type of data it is.
Priorities move the input within the current section. It would need to be defined in the ‘company’ section rather than in the ‘job’ section.
print_r(get_post_meta( $post->ID, ‘custom_field_slug’, true )); return nothing.
Here’s a bit of code from the plugin:
$field_id = get_the_ID();
$field_slug = get_post_meta( $field_id, 'wpjmcf_field_slug', true );
$field_type = get_post_meta( $field_id, 'wpjmcf_field_type', true );
$field_value = get_post_meta( $job_id, $field_slug, true );
$options = explode(",",get_post_meta( $field_id, 'wpjmcf_field_options', true ) );
$out .= '<strong>'.get_the_title() . ':</strong> ';
switch ( $field_type ) {
case 'textarea':
$out .= '<br />'.$field_value;
break;
case 'checkbox':
if( 1 == $field_value ) {
$out .= __( 'Yes', 'wpjmcf' );
} else {
$out .= __( 'No', 'wpjmcf' );
}
break;
case 'file':
$out .= '<a href="'.$field_value.'" target="_blank">'.__( 'Download', 'wpjmcf' ).'</a>';
break;
case 'select':
$out .= $options[ $field_value ];
break;
default:
$out .= get_post_meta( $job_id, $field_slug, true );
break;
}
Does that give you an idea ? The “$options[ $field_value ];” doesn’t make sense for me.
It looks like from that, you just need to find out the field_slug for the meta data. The stored value could then be output with just:
echo get_post_meta( $job_id, $field_slug, true );
The options part is for getting the ‘nice’ name for the selected option, rather than its stored key. To use that you’d need to also know the ID of the option, as his plugin stores it. I don’t know how you’d find that out looking at the above code.
I saw that the plugin does have shortcodes for outputting bits of data. Have you thought of using http://codex.wordpress.org/Function_Reference/do_shortcode instead?
I removed the plugin and just working on your way now. Here’s my code
add_filter( 'submit_job_form_fields', 'frontend_add_region_field' );
function frontend_add_region_field( $fields ) {
$fields['job']['job_region'] = array(
'label' => 'Job Region',
'type' => 'select',
'required' => true,
'options' => array ( 'Choose a region', 'California', 'Palto Alto', 'Another Example' ),
'placeholder' => '',
'priority' => 3
);
return $fields;
}
add_action( 'job_manager_update_job_data', 'frontend_add_region_field_save', 10, 2 );
function frontend_add_region_field_save( $job_id, $values ) {
update_post_meta( $job_id, '_job_region', $values['job']['job_region'] );
}
Now when I use
<?php echo get_post_meta( $post->ID, '_job_region', true ); ?>
It returns a number “2” corresponding to the second value of the select list “Palto Alto” in our example which it is true. Now how to convert this to a text value and show Palto Alto instead of the number ?
Easy; in your ‘options’ define the key and value. e.g.
'0' => 'Choose a region', 'California' => 'California'
Then what will the code be like for output ?
I don’t think so because it also output a number…
You’ll need to add another job after making the key/value changes. It will then SAVE the key as the full text version, ready to output.
Did that, I added new jobs but still output numbers. I give up.
Thanks anyway.
I output with:
<?php echo get_post_meta( $post->ID, '_job_region', true ); ?>
And changed your code to:
add_filter( 'submit_job_form_fields', 'frontend_add_region_field' );
function frontend_add_region_field( $fields ) {
$fields['job']['job_region'] = array(
'label' => 'Job Region',
'type' => 'select',
'required' => true,
'options' => array ( 0 => 'Choose a region', 'California' => 'California', 'Palto Alto' => 'Palto Alto', 'Another Example' => 'Another Example' ),
'placeholder' => '',
'priority' => 3
);
return $fields;
}
add_action( 'job_manager_update_job_data', 'frontend_add_region_field_save', 10, 2 );
function frontend_add_region_field_save( $job_id, $values ) {
update_post_meta( $job_id, '_job_region', $values['job']['job_region'] );
}
It does work 🙂
Indeed, it does! Thank you so much 🙂
Now I’m trying to add this field’s value to jobs permalinks using the filter function do you think that would be possible? Something like:
http://mywebsite.com/jobs/california/apple/visual-designer
Ok I’ve tried with the following code, problem is that the trailing slash isn’t working.
add_filter( 'submit_job_form_save_job_data', 'custom_submit_job_form_save_job_data', 10, 5 );
function custom_submit_job_form_save_job_data( $data, $post_title, $post_content, $status, $values ) {
$job_slug = array();
// Prepend region
if ( ! empty( $values['job']['job_region'] ) )
$job_slug[] = $values['job']['job_region'];
// Prepend with company name
if ( ! empty( $values['company']['company_name'] ) )
$job_slug[] = $values['company']['company_name'];
$job_slug[] = $post_title;
$data['post_name'] = implode( '/', $job_slug );
return $data;
}
Result to: http://mywebsite.com/jobs/californiaapplevisual-designer