Support » Plugin: User Submitted Posts » how to set default feature image If user do not upload a photo.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jeff Starr

    (@specialk)

    Adding to the technique described at WP-Mix:

    // @ http://wp-mix.com/set-attachment-featured-image/
    add_filter('the_content', 'set_featured_image_from_attachment');
    function set_featured_image_from_attachment($content) {
    	global $post;
    	if (has_post_thumbnail()) {
    		// display the featured image
    		$content = the_post_thumbnail() . $content;
    	} else {
    		// get & set the featured image
    		$attachments = get_children(array(
    			'post_parent' => $post->ID,
    			'post_status' => 'inherit',
    			'post_type' => 'attachment',
    			'post_mime_type' => 'image',
    			'order' => 'ASC',
    			'orderby' => 'menu_order'
    		));
    		if ($attachments) {
    			foreach ($attachments as $attachment) {
    				set_post_thumbnail($post->ID, $attachment->ID);
    				break;
    			}
    			// display the featured image
    			$content = the_post_thumbnail() . $content;
    		}
    		// NEW STUFFS
    		else {
    			$default_image = 'featured-image-default.jpg';
    			$content = $default_image . $content;
    		}
    	}
    	return $content;
    }

    Same usage instructions as explained at the original post.

    thank so much jeff, but it not work for me.
    I’ll try to find another way.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘how to set default feature image If user do not upload a photo.’ is closed to new replies.