Tutorial: Adding a new text field for jobs

Note: All code examples are provided for developer reference only. Support does not include debugging code examples.

This tutorial demonstrates how to add a custom field to job submissions and display it on single job listings. For a no-code solution, consider the Field Editor add-on.

Add the field to the frontend

In your theme’s functions.php or a functionality plugin, hook into the submission form:

add_filter( 'submit_job_form_fields', 'frontend_add_benefits_field' );

Then create the function:

function frontend_add_benefits_field( $fields ) {
  $fields['job']['job_benefits'] = array(
    'label'       => __( 'Benefits', 'job_manager' ),
    'type'        => 'text',
    'required'    => true,
    'placeholder' => 'e.g. 401k, health insurance, company car',
    'priority'    => 7
  );
  return $fields;
}

This adds a required benefits text field with priority 7 positioning.

Add the field to admin

Hook into the admin fields filter:

add_filter( 'job_manager_job_listing_data_fields', 'admin_add_benefits_field' );

Then write the function:

function admin_add_benefits_field( $fields ) {
  $fields['_job_benefits'] = array(
    'label'       => __( 'Benefits', 'job_manager' ),
    'type'        => 'text',
    'placeholder' => 'e.g. 401k, health insurance, company car',
    'description' => ''
  );
  return $fields;
}

Note the underscore prefix on the field name; this creates hidden meta automatically.

Display “Benefits” on the single job page

Use an action hook to display the field:

add_action( 'single_job_listing_meta_end', 'display_job_benefits_data' );

Create the display function:

function display_job_benefits_data() {
  global $post;
  $benefits = get_post_meta( $post->ID, '_job_benefits', true );
  if ( $benefits ) {
    echo '
  • ' . __( 'Benefits: ' ) . esc_html( $benefits ) . '
  • '; } }