Output custom field values using PHP

To output any custom fields you have created you can either use Shortcodes or one of the following PHP functions to output the custom field values.

Right now there are multiple functions available, one for job fields, company fields, resume fields, etc. This is for any future enhancements, but currently all functions do the same thing (so technically you could use get_resume_field and with details for a job listing and it will still display right. My Suggestion is to use job, company, or resume for the specific field, and if you are not sure then you can use custom field function.

You can find all of these functions and details on them in theĀ includes/functions.php file under theĀ wp-job-manager-field-editor plugin directory.

I also recommending looking through my Gist on GitHub as this is where I frequently post examples (PHP, JS, etc) for support tickets and I may already have some example code you need:

https://gist.github.com/tripflex

Available Functions


get_job_field / the_job_field

get_job_field( $field_slug, $job_id ) or the_job_field( $field_slug, $job_id )

  • $field_slug is the meta key for the field
  • $job_id optional The job ID you want to get the value from, if $job_id is not specified it will use the current job listing.
  • Using get_job_field will return the value, using the_job_field will echo/print out the field.

get_company_field / the _company_field

get_company_field( $field_slug, $job_id ) or the_company_field( $field_slug, $job_id )

  • $field_slug is the meta key for the field
  • $job_id optional The job ID you want to get the value from, if $job_id is not specified it will use the current job listing.
  • Using get_company_field will return the value, using the_company_field will echo/print out the field.

get_resume_field / the_resume_field

get_resume_field( $field_slug, $resume_id ) or the_resume_field( $field_slug, $resume_id )

  • $field_slug is the meta key for the field
  • $resume_id optional The resume ID you want to get the value from, if $resume_id is not specified it will use the current resume listing.
  • Using get_resume_field will return the value, using the_resume_field will echo/print out the field.

get_custom_field / the_custom_field

get_custom_field( $field_slug, $post_id ) or the_custom_field( $field_slug, $post_id )

  • $field_slug is the meta key for the field
  • $post_id optional The resume/job ID you want to get the value from, if not specified it will use the current resume/job listing.
  • Using get_custom_field will return the value, using the_custom_field will echo/print out the field.

Example Usage

Say I wanted to output a new custom field I created with a meta key of job_salary, this is the PHP code you would add to your job listing template file:

Using get_job_field

Or you could simply use the_job_field function instead:

Using the_job_field

Both of the examples above would output the value of the field if it was set for the job listing. This same method can be used for company, resumes, or any other custom fields.

Show image from custom upload field

 

Total 20 Votes

Tell us how can we improve this post?

+ = Verify Human or Spambot ?