Title: get the post thumbnail
Last modified: August 21, 2016

---

# get the post thumbnail

 *  [vincent soo](https://wordpress.org/support/users/vincent-soo/)
 * (@vincent-soo)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/get-the-post-thumbnail/)
 * Hi Guys,
 * How can I make create other post feature image by using slug?
 * Currently I am using this script
    get_the_post_thumbnail(57, ‘thumbnail’)
 * 57 is post ID
 * But I wanna it to be something like this
    get_the_post_thumbnail(‘my slug’, ‘
   thumbnail’)
 * I don’t wan to use ID to call the post, I wan to call by using slug name, is 
   it possible?

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [Pioneer Web Design](https://wordpress.org/support/users/swansonphotos/)
 * (@swansonphotos)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/get-the-post-thumbnail/#post-3834372)
 * First, what theme template are you using this in…
 * The ID is optional, the default is current post ID.
 * And, see these:
 * [http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail](http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail)
 * [http://www.wprecipes.com/wordpress-function-to-get-postpage-slug](http://www.wprecipes.com/wordpress-function-to-get-postpage-slug)
 *  Thread Starter [vincent soo](https://wordpress.org/support/users/vincent-soo/)
 * (@vincent-soo)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/get-the-post-thumbnail/#post-3834378)
 * Hi Swanson,
 * I am using [Bones themes](http://themble.com/bones/) , Reason I wan it to be 
   slug is because I will turn it to become a custom field, so I can just insert
   slug name instead of ID name.
 *  [Pioneer Web Design](https://wordpress.org/support/users/swansonphotos/)
 * (@swansonphotos)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/get-the-post-thumbnail/#post-3834379)
 * Then use a function to grab the slug of the post id as shown in the second link.
 *  Thread Starter [vincent soo](https://wordpress.org/support/users/vincent-soo/)
 * (@vincent-soo)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/get-the-post-thumbnail/#post-3834385)
 * Thanks for the quick reply…
    Sorry my scripting knowledge is really beginner
 * I have insert this script in function.php
    function the_slug() { $post_data =
   get_post($post->ID, ARRAY_A); $slug = $post_data[‘project-123’]; return $slug;}
 * And in my page.php when I call this function out, it just throw out error
    <?
   php echo get_the_post_thumbnail(the_slug(), ‘thumbnail’); ?>
 * I know the way I insert the_slug() is wrong, I try a lot of way to writing it
   
   the_slug()->ID , I even not using function straight $post_data = get_post($post-
   >ID, ARRAY_A); $slug = $post_data[‘project-123’];
 * <?php echo get_the_post_thumbnail($slug ‘thumbnail’); ?>
 * But all just went wrong…can point me out the correct way of writing it?
    Thank
   you
 *  [Pioneer Web Design](https://wordpress.org/support/users/swansonphotos/)
 * (@swansonphotos)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/get-the-post-thumbnail/#post-3834424)
 * First, use the function the way is was presented…then try:
 *     ```
       <?php $args = array(
       'post_id' => the_slug();,
       'size' => 'thumbnail',
        );
       echo get_the_post_thumbnail($args);
        ?>
       ```
   
 * Above is not tested…need a foreach?
 *  Thread Starter [vincent soo](https://wordpress.org/support/users/vincent-soo/)
 * (@vincent-soo)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/get-the-post-thumbnail/#post-3834480)
 * Hi Swanson,
 * I still can’t get it work, it since like the code from this link have error
    
   [http://www.wprecipes.com/wordpress-function-to-get-postpage-slug](http://www.wprecipes.com/wordpress-function-to-get-postpage-slug)
 * function the_slug() {
    $post_data = get_post($post->ID, ARRAY_A); $slug = $post_data[‘
   post_name’]; return $slug; }
 * <?php echo the_slug(); ?>
 * I try copy and paste exactly without changing any thing and it show error in 
   the page…
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/get-the-post-thumbnail/#post-3834502)
 * get_the_post_thumbnail() only accepts a post id.
    [http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail](http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail)
 * To get the ID from a slug so you can use it in the function use this:
    [http://wordpress.org/support/topic/how-can-i-get-the-page-id-from-a-page-slug](http://wordpress.org/support/topic/how-can-i-get-the-page-id-from-a-page-slug)
 * Here’s an example:
 *     ```
       <?php
       // get the slug from the custom field
       $slug = get_post_meta( $post->ID, 'slug', true );
       if ( '' != $slug ) {
   
       	// get the post id from the custom field slug
       	global $wpdb;
       	$my_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_name = '$slug'" );
   
       	// display the post thumbnail.
       	if ( $my_id ) {
       		echo get_the_post_thumbnail( $my_id , 'thumbnail' );
       	}
   
       }
       ?>
       ```
   

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘get the post thumbnail’ is closed to new replies.

## Tags

 * [feature image](https://wordpress.org/support/topic-tag/feature-image/)
 * [id](https://wordpress.org/support/topic-tag/id/)
 * [image](https://wordpress.org/support/topic-tag/image/)
 * [slug](https://wordpress.org/support/topic-tag/slug/)
 * [thumbnail](https://wordpress.org/support/topic-tag/thumbnail/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 3 participants
 * Last reply from: [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * Last activity: [12 years, 11 months ago](https://wordpress.org/support/topic/get-the-post-thumbnail/#post-3834502)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
