Add select box field
-
Hi All
I wanted to add a special field to the form submission page (and the admin) called: location.
A drop down menu where a user can select location.
I came across this tutorial:
https://wpjobmanager.com/document/tutorial-adding-a-salary-field-for-jobs/
but it is about adding tect field and I need select box + options of course.
anyone knows how to do it?Thanks
-
You can base it on that tutorial, but you a field type of ‘select’ and pass in an array of options. e.g.
'type' => 'select', 'options' => array( 'Location 1', 'Location 2' ),Great! it is working
Is this the only way to add / edit fields?
is there an additional plugin that does that easier?
Thankshamergil,
I’m not sure if it covers your needs but you may find the plugin Predefined Regions by Astoundify of use (it’s free).
It essentially adds a new submenu within WP Job Manager wherein you can add multiple regions. They then become available for selection on all job related pages.
In addition, and if i remember correctly, a toggle option is added to the WP Job Manager settings page, which allows you to use a dropdown select box in your filters instead of a text input (which is the default type for the location filter).
Hope it is of use to you,
DonThanks Don
I’ll definitly check that out@hamergil you may be interested in something like this if you don’t want to write any code – https://plugins.smyl.es/wp-job-manager-field-editor/?in=1
Also, it’d be really great if you’d consider leaving a review too – https://wordpress.org/support/view/plugin-reviews/wp-job-manager#postform π
Hey @bryceadams
thanks for the link. I actually used the above code mike provided but I will definitely consider using this plugin in the future.
I left a review in the link you provided
Thanks.Hey @hamergil
Can you please tell whether you hard coded the locations in that code ?I sort of need to show in the drop down only the locations that exist in the jobs added.
Thanks in advance !
Sure. this is the code I was using:
add_filter( 'submit_job_form_fields', 'frontend_add_region_field' ); function frontend_add_region_field( $fields ) { $fields['job']['job_region'] = array( 'label' => __( 'Region', 'job_manager' ), 'type' => 'select', 'options' => array( 'East', 'West','South', 'North'), 'required' => true, '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'] ); }This added a special “Region” drop down field to my frint end “add job” page.
hope it helpsAfter creating the drop down menu (great tutorial here for those who are interested) – does anyone know how to call values to the front end of wordpress based on the option selected in the select box? I’m not looking to add the dropdown to the front end, I just wanted to call text specific to each option.
Been trying variations of the code below and it’s not working:
<?php // adds custom dropdown field to frontend $dropdown_values = get_post_meta( $post->ID, 'dropdown_select', true) ; $dropdown_ai_value = $field['id']; if( ! empty( $dropdown_values ) ) { echo $dropdown_ai_value; } ?>I’ve used the below code to pull in text values and it’s worked perfectly – how do you edit the code to be select box specific?
<div class="mymetavaluekey1" style="font: Helvetica, Arial, sans-serif font-size: 18px font-style: italic text-align: center;"> <?php // adds custom title field to frontend $meta_values = get_post_meta( get_the_ID(), '_my_meta_value_key', true) ; if( ! empty( $meta_values ) ) { echo $meta_values; } ?> </div>Hey dallashuggins.
I used Advanced Custom Fields plugin to create fields easily then passed this to WP job manager template files.
For example, I added a whole bunch of text fields so the job description could have subheadings using this plugin which is very easy to do. Then I assigned them to the job_listing post type so they only appeared when editing a job post type and not a generic post or page.
Then in my WP job manager template files I added:
$fields = get_field_objects(); if( $fields ) { foreach( $fields as $field_name => $field ) { echo '<div>'; echo '<h4>' . $field['label'] . '</h4>'; echo $field['value']; echo '</div>'; } }This will grab the fields, and if content exists for that field, outputs the result.
I hope you find this easier than editing core functions.php files. I sure as hell did.
Hi Mike Jolley,
I’ve included the following to my custom job listing data field in my functions.php.
‘type’ => ‘select’,
‘options’ => array( ‘Location 1’, ‘Location 2’ ),So it now looks like this:
add_filter( ‘job_manager_job_listing_data_fields’, ‘admin_add_nhs_grade_field’ );
function admin_add_nhs_grade_field( $fields ) {
$fields[‘_nhs_grade’] = array(
‘label’ => __( ‘NHS Grade’, ‘job_manager’ ),
‘type’ => ‘select’,
‘options’ => array( ‘HCPC Paramedics’, ‘IHCD Technicians’ ,’HCPC Paramedics with CP Qualification’ ),
‘placeholder’ => ‘IHCD FPOS or Equivalent’,
‘description’ => ”
);
return $fields;}
However all thats getting saved in the database is numbers (0’s, 1’s, 2’s) they all relate to which option I chose in the job listing within the CMS. But no actual value is being saved. Such as ‘HCPC Paramedics’ or ‘IHCD Technicians’.
Do you know why?
Thanks,
Daniel.
danny_wobble set the key and value in your array of options.
array( 'HCPC Paramedics'=> 'HCPC Paramedics' )
The topic ‘Add select box field’ is closed to new replies.