2

I have been working on a custom add-on for WP Job Manager where I modify, via filters, the content displayed. I've used many of the tutorials on www.wpjobmanager.com/documentation, but I'm stuck on one point.

I'm trying to recreate a feature from the Resumes add-on (demo here) where you can add additional education or experience fields. I am trying to recreate that feature in the main WP Job Manager plugin to populate an optional subfield for addresses.

This is a scaled down version of the code I have for now: http://pastebin.com/fAVq9vfu

I have successfully added the fields and subfields to the form (there is a separate template file that renders the form). They also register in the global $_POST variable as shown when I do a var_dump in the Preview template (sample screenshot), but I am messing up somewhere when it comes to storing the values. None of the fields with subfileds are saving in the post meta data table. I've tried a few options, most recently by including and having my class extend WP_Job_Manager_Forms Class (https://github.com/mikejolley/WP-Job-Manager/blob/master/includes/class-wp-job-manager-forms.php). I believe I can accomplish what I am trying to do via the included filters, but I'm not sure which one or how to do it.

I believe I might need to call get_posted_fields() somewhere, because I'm not entirely sure it is catching my custom get_posted_{subfield}_field methods.

Does anyone have any tips?

0

I see a few things missing in your snippet/code.

  1. Each field (your location ones) need to include priority:

    'priority' => 19,

  2. You defined 'type' as 'location' but did not define that field type. The repeated files in resume manager where you based this code on defines template files for education, experience etc. To define your own filter on 'job_manager_locate_template'. Quick example https://gist.github.com/mikejolley/76d8b538fe489377793b You'll need a template file for each of your repeated fields. We may make this simpler in the future, but as I explained via support, repeated fields are new :)

1
  • Thanks! I have added priorities and have filtered 'job_manager_locate_template' to look in the plugin directory for repeated field templates. I already had templates and they rendered fine, I just had them in my Child Theme. My only issue now is that the values are not retrieved when get_posted_fields() is executed in core. If you look at lines 303 to 360 of my snippet, you will see what I have typed up that should execute when the function is called. They are however not executing within the plugin. If I put that code in functions.php it works. Is it possible to have that code in the plugin? – ahurleb May 19 '15 at 4:10
1

We can different types of fields for 'Resume Manager' & save it. We can achieve this via filter, as follows,

//code to add custom field for Resume Manager on front end
add_filter( 'submit_resume_form_fields', 'wdm_customize_resume_fields' );

function wdm_customize_resume_fields($fields)
{
   $fields['resume_fields']['candidate_address'] = array(
    'label'       => __( 'Your Address', 'wp-job-manager-resumes' ),
    'type'        => 'text',
    'required'    => false,
    'description' => __('Add your address here','wp-job-manager-resumes'),
    'priority'    => 2
    );

   return $fields;
}

Here you can specify new field, add it's label, type for it as well as specify it's location using 'priority'.

Now we need to save fields, we can use following code,

add_action( 'resume_manager_update_resume_data', 'wdm_save_resume_custom_field', 10, 2 );

function wdm_save_resume_custom_field( $resume_id, $values ) {

  if(!empty($resume_id) && !empty($values)) {

     if(isset($values['resume_fields']['candidate_address']) {

       update_post_meta( $resume_id, '_candidate_address', $values['resume_fields']['candidate_address'] );
     }
  }
}

This will update Candidate's address in '_candidate_address' meta key, if it is set.

This saved field needs to be shown in, Dashboard as well. We can achieve this as follows,

add_filter( 'resume_manager_resume_fields', 'wdm_resume_fields_dashboard' );

function wdm_resume_fields_dashboard($fields){

   $fields['_candidate_address'] = array(
    'label'       => __( 'Your Address', 'wp-job-manager-resumes' ),
    'placeholder' => __( 'Add your address here', 'wp-job-manager-resumes' ),
    'type'        => 'text'
);

  return $fields;
}
7
  • Thanks so much for the reply, I guess I was not clear though. I am not looking to filter into the resume add-on. I was using a feature of the resume add-on as a reference for what I am trying to replicate in a custom add-on to the core WP Job Manager plugin. I am confident adding individual fields as you have demonstrated. What I am trying to do is to have a field with it's own subfields save in the wppostmeta table. If you view my pastebin link, look at line 126 and you will see the new fields I'm referring to. Line 209 is where I'm thinking I need to work on. – ahurleb May 13 '15 at 3:53
  • Apologies, didn't get much time to try out entire code. We assume,Contact name,title fields for 'Property Contact' are rendered properly. You can try below code, if(isset($values['property']['property_contact'] ['contact_name'])) { update_post_meta($job_id,'_contact_name',$values['property']['property_contact']['contact_name']); } else { update_post_meta($job_id,'_contact_name','Value not set'); } This will set post_meta value, if it gets value, otherwise dummy text added 'Value not set' will be saved. If you can tell us, '$values' output, we will be able to help you better. – Domain May 13 '15 at 9:54
  • It is returning 'Value not set' when I put that code in the custom 'update_job_data' function which is what goes into the 'job_manager_update_job_data' action. I'm guessing that my get_posted_contact_field function is not being executed properly. – ahurleb May 14 '15 at 3:00
  • In function, get_repeated_field() $key & $fields['fields'] are passed. This will pass 'contact_name', 'contact_title', 'contact_email' etc fields, right? When you fetch, array_keys($fields) & check for first key, it will be 'contact_name' key, and it is checked with $field_prefix. There may be some problem here. Also, if 'contact_name' is empty & other fields are filled, below code may not execute. – Domain May 14 '15 at 4:49
  • I can't try right now, but I will check tomorrow and see. I'll pull out the comparison against $field_prefix and see if it can clear that step. I pulled that bit directly from the resume add-on that they made for WP Job Manager so I'm pretty sure it should all work. I was thinking in might have something to do with the way I declared the class or function and if the core plugin even recognizes the functions... Obviously that hasn't gotten me very far though 😄. Thanks for your help so far. I'll keep you posted – ahurleb May 14 '15 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.