Support » Plugin: Custom Content Type Manager » PDF in a custom field

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Contributor fireproofsocks

    (@fireproofsocks)

    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?

    Thread Starter marknolan

    (@marknolan)

    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?

    print_custom_field(‘customfieldname:to_link’)

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    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.

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    Looks like WP stores that bit in the guid field. So you could do this:

    print_custom_field('customfieldname:get_post','guid');
    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    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?

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    Yeah: use the [+guid+] placeholder.

    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/

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    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.

    print_custom_field('customfieldname:get_post','guid');

    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!

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    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>

    Thanks sv3 – that’s the one 🙂

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘PDF in a custom field’ is closed to new replies.