Skip to content

Instantly share code, notes, and snippets.

@BhargavBhandari90
Created December 6, 2024 07:20
Show Gist options
  • Save BhargavBhandari90/f99e0258a901440715481ec24fe49b70 to your computer and use it in GitHub Desktop.
Save BhargavBhandari90/f99e0258a901440715481ec24fe49b70 to your computer and use it in GitHub Desktop.
Add field to job manager submit job form
<?php
/**
* Add a Field to the Job Submission Form:
*/
add_filter( 'submit_job_form_fields', 'custom_job_submission_fields' );
function custom_job_submission_fields( $fields ) {
$fields['job']['custom_field'] = array(
'label' => __( 'Custom Field', 'text-domain' ),
'type' => 'text',
'required' => false,
'placeholder' => __( 'Enter custom value', 'text-domain' ),
'priority' => 10,
);
return $fields;
}
/**
* Save the Field Value:
*/
add_action( 'job_manager_update_job_data', 'save_custom_job_field', 10, 2 );
function save_custom_job_field( $job_id, $values ) {
if ( isset( $values['job']['custom_field'] ) ) {
update_post_meta( $job_id, '_custom_field', sanitize_text_field( $values['job']['custom_field'] ) );
}
}
/**
* Display the Field Value:
*/
add_action( 'single_job_listing_meta_end', 'display_custom_job_field' );
function display_custom_job_field() {
global $post;
$custom_field = get_post_meta( $post->ID, '_custom_field', true );
if ( ! empty( $custom_field ) ) {
echo '<li>' . esc_html( $custom_field ) . '</li>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment