Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Last active May 12, 2022 12:14
Show Gist options
  • Select an option

  • Save mikejolley/4b495f544bb632757e27 to your computer and use it in GitHub Desktop.

Select an option

Save mikejolley/4b495f544bb632757e27 to your computer and use it in GitHub Desktop.
Resume Manager Repeated Rows Example. Requires 1.11.4
/**
* Return an array of fields which will repeat (have multiple rows)
*
* Subfields should be named group_fieldname[]
*
* @return array
*/
function get_custom_repeated_field_fields() {
return array(
'field1' => array(
'label' => __( 'Field 1', 'wp-job-manager-resumes' ),
'name' => 'custom_repeated_field_field1[]',
'type' => 'select',
'options' => array(
'option-1' => 'Option 1',
'option-2' => 'Option 2'
),
'placeholder' => '',
'description' => '',
'required' => true
),
'field2' => array(
'label' => __( 'Field 2', 'wp-job-manager-resumes' ),
'name' => 'custom_repeated_field_field2[]',
'type' => 'text',
'placeholder' => __( 'Field 2 Placeholder', 'wp-job-manager-resumes' ),
'description' => '',
'required' => true
)
);
}
/**
* Add a repeated field.
*
* This example requires a file in your theme folder: yourtheme/job_manager/form-fields/custom_repeated_field-field.php to control the output of the form field.
*/
function add_custom_repeated_field( $fields ) {
$fields['resume_fields']['custom_repeated_field'] = array(
'label' => __( 'Custom Value(s)', 'wp-job-manager-resumes' ),
'type' => 'repeated',
'required' => false,
'placeholder' => '',
'priority' => 9,
'fields' => get_custom_repeated_field_fields(),
'description' => __( 'Description for this group of fields', 'wp-job-manager-resumes' ),
'add-row-text' => __( 'Add Repeated Field', 'wp-job-manager-resumes' )
);
return $fields;
}
add_filter( 'submit_resume_form_fields', 'add_custom_repeated_field' );
/**
* Add a meta box to the backend to output this fields values.
*/
function add_custom_repeated_field_meta_box() {
add_meta_box( 'custom_repeated_field', __( 'Repeated Field', 'wp-job-manager-resumes' ), 'custom_repeated_field_meta_box', 'resume', 'side', 'low' );
}
add_action( 'add_meta_boxes', 'add_custom_repeated_field_meta_box' );
/**
* Add meta box contents.
*
* _custom_repeated_field needs replacing with the meta key for your fields.
*
* Requires resumes 1.11.3
*/
function custom_repeated_field_meta_box( $post ) {
WP_Resume_Manager_Writepanels::repeated_rows_html( __( 'Custom Repeated Row', 'wp-job-manager-resumes' ), get_custom_repeated_field_fields(), get_post_meta( $post->ID, '_custom_repeated_field', true ) );
}
/**
* Save the meta box.
*
* _custom_repeated_field needs replacing with the meta key for your fields.
*
* Requires resumes 1.11.3
*/
function save_custom_repeated_field( $post_id, $post ) {
WP_Resume_Manager_Writepanels::save_repeated_row( $post_id, '_custom_repeated_field', get_custom_repeated_field_fields() );
}
add_action( 'resume_manager_save_resume', 'save_custom_repeated_field', 2 );
@AtrumGeost
Copy link
Copy Markdown

Hello,
This code seems really interesting. In order to use it, do I have to write it in my theme's functions.php file?

Regards

@globalreson8
Copy link
Copy Markdown

Awesome!
It's all working on the backend but on the frontend the custom fields are not saving....? The values entered into the custom fields do NOT show:

  1. On resume preview
  2. On the backend in the meta fields
  3. On the resume after is has been approved

But somehow the values remain on the frontend when I go back to edit the resume>

To confirm - when I create or edit the resume from the backend it all works correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment