Created
December 1, 2014 10:50
-
-
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
This file contains hidden or 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 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