The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

How do I display an image from a custom field in a custom post type column? (1 post)

  1. fcarthy
    Posted 5 years ago #

    I have a custom post type, and I have also modified the columns in the admin panel to show certain fields. The only problem is that when I try to pull the image from a custom field I created all posts pull the same image. The funny part is that the image that is pulled is always the first image that was uploaded to ANY post type. This is what I have:

    add_filter("manage_edit-event_columns", "events_edit_columns");
    add_theme_support( 'post-thumbnails', array( 'event' ) );
    function events_edit_columns($columns){
      $columns = array(
        "cb" => "<input type=\"checkbox\" />",
        "title" => "Event Title",
        "date" => "Event Date",
        "drink_name" => "Drink",
        "venue_name" => "Venue",
        "drink_image" => "Drink Image",
      return $columns;
    function events_custom_columns($column){
      global $post;
      switch ($column) {
        case "drink_name":
          $custom = get_post_custom();
          echo $custom["drink_name"][0];
        case "venue_name":
          $custom2 = get_post_custom();
          echo $custom2["venue_name"][0];
        case "drink_image":
    			$width = (int) 50;
    			$height = (int) 50;
    				$thumbnail_id = get_post_meta( $post_id, 'drink_image', true );
    				// image from gallery
    				$attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') );
    				if ($thumbnail_id)
    					$thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
    				elseif ($attachments) {
    					foreach ( $attachments as $attachment_id => $attachment ) {
    						$thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true );
    					if ( isset($thumb) && $thumb ) {
    						echo $thumb;
    					} else {
    						echo __('None');

    Here's an example:

Topic Closed

This topic has been closed to new replies.

About this Topic