Last active
November 20, 2018 21:27
-
-
Save tripflex/79c291827063b74614173f2f51b60cda to your computer and use it in GitHub Desktop.
Save Company Listings (WPDrift Plugin) meta fields to job listing meta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'job_manager_update_job_data', 'smyles_save_company_data_to_job_listing', 20, 2 ); | |
/** | |
* Save Company Listings (WPDrift Plugin) meta fields to job listing meta | |
* | |
* | |
* @since 11.20.2018 | |
* | |
* @param $job_id | |
* @param $data | |
*/ | |
function smyles_save_company_data_to_job_listing( $job_id, $data ){ | |
$company_id = isset( $_POST['company_id'] ) ? absint( $_POST['company_id'] ) : get_post_meta( $job_id, '_company_id', true ); | |
if( empty( $company_id ) ){ | |
return; | |
} | |
/** | |
* Mapping of Company metakeys to Job meta keys, must match this pattern: | |
* 'company_meta_key' => 'job_meta_key' | |
* | |
* Make sure to include prepended underscore as all company and job/resume listing data is hidden meta, which means | |
* it will be saved using the meta key + an underscore (before meta key) | |
*/ | |
$mappings = array( | |
'_company_logo' => '_company_logo', | |
'_company_twitter' => '_job_listing_twitter' | |
); | |
foreach( (array) $mappings as $company_meta_key => $job_meta_key ){ | |
$value = get_post_meta( $company_id, $company_meta_key, true ); | |
update_post_meta( $job_id, $job_meta_key, $value ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment