I have a custom field for pdfs set up as image (have tried media aswell) and would like to read out the link of the file with print_custom_field(‘customfieldname:to_image_src’)
all it outputs is the default mime-type image.
how can i get to the url of the pdf?
If you want to link to PDF (or to any image, or any related post), use a different filter, e.g. https://code.google.com/p/wordpress-custom-content-type-manager/wiki/to_link_OutputFilter or any of the WordPress functions that convert a post ID to data, e.g. get_permalink().
I am assuming you defined your field as a media field?
yes i’m using media field.
ok. so if i use to_link it shows me the permalink to the post.
i’m sorry for beeing thick – but how do i access the attached pdf file directly?
It’s probably something WP has obfuscated under the guise of “being helpful”. I suspect the permalink is to the “media page” which contains the PDF, but not the PDF itself. In that case, it would take some digging. I would use the get_post filter to see what custom fields are available on that item — digging around to see where the #!$%! wp buried the data you need is much easier in PHP, so I would do something like this:
$rel = get_custom_field('customfieldname:get_post'); print_r($rel); // OR more raw yet $post_id = get_custom_field('customfieldname:raw'); $rel=get_post_complete($post_id); print_r($rel);
print_r will show you what fields are available in the related object, and from there you can see if there’s anything helpful to you.
Looks like WP stores that bit in the guid field. So you could do this:
Example added to the docs: https://code.google.com/p/wordpress-custom-content-type-manager/wiki/Media
Is there a way to do this using the summarize post short code? I want to display a list of custom posts and the link to the pdf custom field I created?
Yeah: use the
Thank you for the quick response, when I do the [+guid+] placeholder, it creates text that displays the link of the page the pdf is on, not the actual link to the pdf –
You can view it here: http://taskcrate.com/clientblog6/testing/
This is just a matter of debugging: you get the link to the page, the page has a link to the pdf. Look at the wiki — you can use the get_post output filter as is demonstrated there.
I was able to get this to work – but it misses the “/” after “uploads”. To the path is ALMOST correct. Goes to /uploads2013/06/this.pdf instead of /uploads/2013/06/this.pdf. Just one slash needed after “uploads”. Any way to add that in? Thanks!
Sounds like something WP is mangling… get_post doesn’t manipulate the URL, it just returns the stored value. A good cross-check would be to view the relevant row in the wp_posts table and see what value is actually stored.
Found it! There’s a _wp_attached_file call that will get the file path after /uploads. So I did this..
<a href="http://localhost:8888/wp-content/uploads/<?php print_custom_field('custom_field_name:get_post','_wp_attached_file'); ?>">Click For A PDF</a>
- The topic ‘PDF in a custom field’ is closed to new replies.