Tagged: 

Viewing 3 reply threads
  • Author
    Posts
    • #3608
      cosmocanuck
      Member

      Hi! I’ve just added a file upload field so I can add a custom header to certain posts. Here’s my code (I’m using Genesis but that doesn’t seem to (hopefully) have anything to do with the issue at hand…)

      add_action ( 'genesis_before_content', 'aadc_casestudy_header' ); 
      
      function aadc_casestudy_header() {
      
      	$image_ids = get_post_meta($post->ID, 'case-study-header-image');
      
      	print_r($image_ids);
      	
      	echo '<div style="color:white;">.</div>';
      	
      	if ($image_ids) {
       
      		foreach ($image_ids as $image)
      		{
      		  $myupload = get_post($image); 
      		  $title = $myupload->post_title;
      		  $description = $myupload->post_content;
      		  $caption = $myupload->post_excerpt;
       
      		  echo 'title:' . $title;
      		  echo 'description:' . $description;
      		  echo 'caption:' . $caption;
       
      		 echo '<img src="' . wp_get_attachment_url($image) . '"/>';
       
      		  print_r($myupload); // Displays all data
      		}
      	}
      }
      

      The $image_ids variable seems to be empty even though I’ve added an image using the file upload field.

      I added the echo '<div style="color:white;">.</div>'; line to make sure the function was even working, and that white dot above the content area does indeed display. But the print_r and of course the three “echo” lines produce nothing. (See attached screen shot).

      Hope you can point me in the right direction – or suggest something obvious I’m missing!

      Thanks!
      adam

      Attachments:
      You must be logged in to view attached files.
    • #3611
      Steve
      Keymaster

      You are trying to access the $post global without calling it first. This is standard PHP not a Piklist thing. Add global $post; to your function:

      function aadc_casestudy_header() {
      
      global $post;
      
      	$image_ids = get_post_meta($post->ID, 'case-study-header-image');
      
      
    • #3612
      cosmocanuck
      Member

      Thanks Steve!

    • #3621
      Steve
      Keymaster

      You’re very welcome. Closing ticket.

Viewing 3 reply threads
  • The topic ‘Upload field seemingly not functioning…’ is closed to new replies.