Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ( ! function_exists( 'set_my_featured_image' ) ) {
- add_action( 'save_post', 'set_my_featured_image' );
- function fb_set_featured_image() {
- $postID = get_the_ID();
- if ( has_post_thumbnail( $postID ) ) return NULL;
- if( get_post_type( $postID ) != 'post' ) return NULL;
- $args = array(
- 'numberposts' => 1,
- 'order' => 'DESC', // ASC - pierwsza, DESC -ostatnia
- 'orderby' => 'menu_order', // rand - losowo
- 'post_mime_type' => 'image',
- 'post_parent' => $postID,
- 'post_status' => NULL,
- 'post_type' => 'attachment'
- );
- $attached_image = get_children( $args );
- if ( $attached_image ) {
- foreach ( $attached_image as $attachment_id => $attachment )
- set_post_thumbnail( $postID, $attachment_id );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement