Title: Adding Custom Field&#8230;
Last modified: August 18, 2016

---

# Adding Custom Field…

 *  [Lindsey](https://wordpress.org/support/users/lalindsey/)
 * (@lalindsey)
 * [18 years, 5 months ago](https://wordpress.org/support/topic/adding-custom-field/)
 * I want to add a custom field value to a plugin I am using. The plugin is the 
   [Daily Top Ten Posts](http://www.alleba.com/blog/2007/03/27/wordpress-plugin-daily-top-10-posts/).
 * So, I found the part of the code I need to edit to control the output of the 
   list of entry titles. What I want to do is use a custom field that I have to 
   display the image.
 * So, this is the current code:
 *     ```
       if ($widgets_num) {
       	foreach ($widgets as $widget) {
       	$postnum = $widget->postnum;
       	$postcount = $widget->postcount;
         $id_post = $widget->ID;
         $title_post = $widget->post_title;
         if ($perma) {
         $home_url_perma = get_permalink($id_post);
         <strong>$postpic = get_post_custom_values("PostImage");
       </strong>  $todays_widget_temp .= "<strong><p class=\"news-img\"><img src=\"$postpic\" alt=\"$title_post\">
       <div class=\"news-txt\"><a href=\"$home_url/?p=$id_post\" title=\"$text\">$title_post</a> <span class=\"count\">($postcount$views)</span></div></strong>\n";
         } else {
         $todays_widget_temp .= "<strong><p class=\"news-img\"><img src=\"$postpic\" alt=\"$title_post\">
       <div class=\"news-txt\"><a href=\"$home_url/?p=$id_post\" title=\"$text\">$title_post</a> <span class=\"count\">($postcount$views)</span></div></strong>\n";
       	  }
       	 }
         }
       ```
   
 * *Note: I’ve added this variable to try to get my custom field to display: **$
   postpic = get_post_custom_values(“PostImage”);
    
   *
 * Now, everything works fine, EXCEPT, I can’t get the $postpic to display. Which
   is a custom variable I added myself to call the “PostImage” custom field.
 * The only they that displays in the HTML output for the $postpic value is “Array”.
   Not any actual values.
 * I’ve also tried using
 * `get_post_meta($post->ID, "PostImage", true);`
 * in place of
 * `get_post_custom_values("PostImage")`
 * As you can see I’m not php expert, so I’m struggling trying to pull the “PostImage”
   custom value and placing it within this plugin.
 * If anyone could give me some advice, or show me how to do it I would greatly,
   greatly appreciate it.
 * Thanks,
    Lindsey

Viewing 1 replies (of 1 total)

 *  [cwoodside](https://wordpress.org/support/users/cwoodside/)
 * (@cwoodside)
 * [18 years, 5 months ago](https://wordpress.org/support/topic/adding-custom-field/#post-655486)
 * Hi lalindsey,
    I’m assuming that you are looking to show only one selected image
   with each post. If I’m correct you may want to try looking at this anther way,
   here is what I am thinking:
 * 1. Create a custom field called “wp_uploadname”, this field will be used to enter
   the name of the image you would like to appear (including the extension).
 * 2. Update your theme so that you use code similar to this for each post:
 * `<img src="<?php bloginfo('wpurl'); ?>/wp-content/uploads/<?php the_time('Y/m/');?
   ><?php $key ="wp_uploadname"; echo get_post_meta($post->ID, $key, true); ?>" 
   alt="" width="" height="" />`
 * “wp_uploadname” represents the name of your custom field.
 * 3. Create a new post, upload an image in the standard way (without actually attaching
   it to the post body) then type the name of that image (including extension) in
   the custom field you had created.
 * 4. After doing this the code from step two will resolve to something like this:
 * `<img src=”[http://yourwebsite.com/wp-contents/uploads/2007/10/myimage.jpg&#8221](http://yourwebsite.com/wp-contents/uploads/2007/10/myimage.jpg&#8221);
   alt=”” height=”” width=”” />’
 * I entered “2007/10” for example purpose the dates would actually change to reflect
   when each post was created. Also “myimage.jpg” would actually be the image name
   that you had entered in the custom field, which of course will have to actually
   match the uploaded image name and file extension.
 * Hope this helps,
    Chet

Viewing 1 replies (of 1 total)

The topic ‘Adding Custom Field…’ is closed to new replies.

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [variables](https://wordpress.org/support/topic-tag/variables/)

 * 1 reply
 * 2 participants
 * Last reply from: [cwoodside](https://wordpress.org/support/users/cwoodside/)
 * Last activity: [18 years, 5 months ago](https://wordpress.org/support/topic/adding-custom-field/#post-655486)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
