Tagged: upload
- This topic has 3 replies, 2 voices, and was last updated 6 years, 10 months ago by
Steve.
-
AuthorPosts
-
-
April 9, 2015 at 2:10 pm #3608
cosmocanuckMemberHi! 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!
adamAttachments:
You must be logged in to view attached files. -
April 9, 2015 at 4:57 pm #3611
SteveKeymasterYou 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'); -
April 9, 2015 at 6:08 pm #3612
cosmocanuckMemberThanks Steve!
-
April 10, 2015 at 10:18 am #3621
SteveKeymasterYou’re very welcome. Closing ticket.
-
-
AuthorPosts
- The topic ‘Upload field seemingly not functioning…’ is closed to new replies.