Tutorial: Adding a new custom field for submitting company

Note: All code examples on this site are provided for developer reference/guidance only and we cannot guarantee that they will always work as expected. Our support policy does not include assistance with modifying or debugging code from any code examples, and they may be changed or removed if we find they no longer work due to changes in our plugins.

This tutorial shows how to edit fields based on the Editing Company Submission fields doc and then output it on a single job listing.

Add the field to the frontend

Open up your theme’s functions.php file, or even better, use a functionality plugin such as Code Snippets, and create a function to append a new field to the company submit section. First, hook it in:

1 add_filter( 'submit_company_form_fields', 'frontend_add_employee_field' );

Then write the function:

1 2 3 4 5 6 7 8 9 10 function frontend_add_employee_field( $fields ) { $fields['company_fields']['company_employee'] = array( 'label' => __( 'Number of Employees', 'wp-job-manager-company-listings' ), 'type' => 'text', 'required' => true, 'placeholder' => 'e.g. 200-300', 'priority' => 8 ); return $fields; }

This adds a company_employee text field in the submit company form that has the label “Number of Employees”, is required, has 'e.g. 200-300' placeholder, and is ordered in 8th position.

Fields added using the above code will be saved to the job listing automatically.

Add the field to admin

Again in theme functions.php, hook in your custom function:

1 add_filter( 'company_listings_company_fields', 'admin_add_employee_field' );

Then write your custom function:

1 2 3 4 5 6 7 8 9 function admin_add_employee_field( $fields ) { $fields['_company_employees'] = array( 'label' => __( 'Number of Employees', 'wp-job-manager-company-listings' ), 'type' => 'text', 'placeholder' => 'e.g. 200-300', 'description' => '' ); return $fields; }

This adds a text field to the admin meta box named “Number of Employees”.

 

Note, the field name is prepended with a ‘_’. This is because Company Listings makes your new fields hidden meta by prepending theme with an underscore. This is normal.