php – Adding a custom meta field with default NULL value which is not selectable

Question

Good morning,

I have a jobboard which makes use of the plugin WordPress Job Manager. I’ve created some custom meta fields for job listings. One of those fields is a select field, where the user can select one option from a list. These are the functions which I used to add these fields.

add_filter( 'submit_job_form_fields', 'frontend_add_stageniveau_field' );
function frontend_add_stageniveau_field( $fields ) {
  $fields['job']['job_stageniveau'] = array(
    'label'       => __( 'Opleiding', 'job_manager' ),
    'type'        => 'select',
    'required'    => true,
    'options' => array('MBO' => 'MBO', 'HBO' => 'HBO', 'Universiteit' => 'Universiteit', 'Anders' => 'Anders'),
    'placeholder' => '',
    'priority'    => 7
  );
  return $fields;

add_filter( 'job_manager_job_listing_data_fields', 'admin_add_stageniveau_field' );
function admin_add_stageniveau_field( $fields ) {
  $fields['_job_stageniveau'] = array(
    'label'       => __( 'Opleiding', 'job_manager' ),
    'type'        => 'select',
    'options' => array('MBO' => 'MBO', 'HBO' => 'HBO', 'Universiteit' => 'Universiteit', 'Anders' => 'Anders'),
    'placeholder' => '',
    'description' => ''
  );
  return $fields;
}

After adding these functions the default value of the field ‘job_stageniveau’ is MBO, since this is the first value in the list. How can I make sure that the default value is NULL, but also make sure that it’s not possible for the user to save the form if the value of ‘job_stageniveau’ is still set to NULL.

Thanks in advance.

0
waffeltje 2 years 2022-03-19T05:23:39-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse