Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Created December 1, 2014 10:50
Show Gist options
  • Select an option

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

Select an option

Save mikejolley/e8094a1e78e939d0d746 to your computer and use it in GitHub Desktop.
Enable job thumbnails and set first attached image as the thumbnail on submission
<?php
// Add post type image support
add_action( 'init', 'enable_job_thumbnails', 50 );
function enable_job_thumbnails() {
add_post_type_support( 'job_listing', 'thumbnail' );
}
// Set first uploaded attached image as thumbnail
add_action( 'job_manager_update_job_data', 'job_manager_update_job_data_set_thumbnail' );
function job_manager_update_job_data_set_thumbnail( $job_id ) {
$images = get_posts( 'fields=ids&post_type=attachment&post_mime_type=image&post_parent=' . $job_id );
if ( $images ) {
set_post_thumbnail( $job_id, $images[0] );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment