Skip to content

Instantly share code, notes, and snippets.

@jawngee
Created January 15, 2019 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jawngee/d1e423a369c56c918a94f442d56693cd to your computer and use it in GitHub Desktop.
Save jawngee/d1e423a369c56c918a94f442d56693cd to your computer and use it in GitHub Desktop.
Fix for MyListing Theme
<?php
function fixJobAttachmentURL($parentPostID, $url) {
global $wpdb;
$path = parse_url($url, PHP_URL_PATH);
$imageName = basename($path);
$query = $wpdb->prepare("select ID from {$wpdb->posts} where guid like %s and post_type='attachment' and post_parent=%d order by ID desc limit 1", '%'.$wpdb->esc_like($imageName), $parentPostID);
$attachmentID = $wpdb->get_var($query);
if (!empty($attachmentID)) {
$url = wp_get_attachment_image_url($attachmentID, 'full');
}
return $url;
}
add_action( 'job_manager_update_job_data', function($job_id, $values) {
global $wpdb;
$gallery_images = get_post_meta($job_id, '_job_gallery');
if (!empty($gallery_images)) {
for($i = 0; $i < count($gallery_images); $i++) {
for($c = 0; $c < count($gallery_images[$i]); $c++) {
$gallery_images[$i][$c] = fixJobAttachmentURL($job_id, $gallery_images[$i][$c]);
}
}
update_post_meta($job_id, '_job_gallery', $gallery_images[0]);
}
$job_logo = get_post_meta($job_id, '_job_logo');
if (!empty($job_logo)) {
$job_logo[0] = fixJobAttachmentURL($job_id, $job_logo[0]);
update_post_meta($job_id, '_job_logo', $job_logo[0]);
}
$job_cover = get_post_meta($job_id, '_job_cover');
if (!empty($job_cover)) {
$job_cover[0] = fixJobAttachmentURL($job_id, $job_cover[0]);
update_post_meta($job_id, '_job_cover', $job_cover[0]);
}
}, 1000, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment