Get Attachment URL – Using it outside the loop?
-
I added a upload custom field to a post that returns a list of PDF files related the the post.
The code I am using, which is working fine, is like this:
<!-- Custom Links for Events Page --> <div class="event-file-downloads"> <?php $pdfdownloadlink = get_post_meta($post->ID, 'pdfdownloadlink', true); foreach($pdfdownloadlink as $pdfdownloadlink) { $file_attributes = wp_get_attachment_url( $pdfdownloadlink['file-upload'] ); echo '<strong>File Downloads: </strong>'; echo '<a href="' . $file_attributes . '" >'; echo '[ '; echo $pdfdownloadlink['file-link-name']; echo ' ] '; echo '</a>'; } ?> </div> <!-- End Custom Links for Events Page -->
What I need to do is call this outside the loop. Most of what I have seen uses something like this to call custom fields outside the loop:
<?php global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta($postid, 'customField', true); ?>
I tried adding global $wp_query; to the original code, that didn’t work. I am just not sure how to modify it to get it to work. Any help anyone could offer would be appreciated.
Thanks.
https://www.ads-software.com/extend/plugins/custom-fields-creator/
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Get Attachment URL – Using it outside the loop?’ is closed to new replies.