WordPress.org

Ready to get started?Download WordPress

Forums

Custom Content Type Manager
[resolved] PDF in a custom field (14 posts)

  1. marknolan
    Member
    Posted 1 year ago #

    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?

    thanks,
    mark

    http://wordpress.org/extend/plugins/custom-content-type-manager/

  2. fireproofsocks
    Member
    Plugin Author

    Posted 1 year ago #

    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?

  3. marknolan
    Member
    Posted 1 year ago #

    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')

  4. fireproofsocks
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  5. fireproofsocks
    Member
    Plugin Author

    Posted 1 year ago #

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

    print_custom_field('customfieldname:get_post','guid');
  6. fireproofsocks
    Member
    Plugin Author

    Posted 1 year ago #

  7. TaskCrate
    Member
    Posted 1 year ago #

    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?

  8. fireproofsocks
    Member
    Plugin Author

    Posted 1 year ago #

    Yeah: use the [+guid+] placeholder.

  9. TaskCrate
    Member
    Posted 1 year ago #

    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/

  10. fireproofsocks
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  11. sv3
    Member
    Posted 1 year ago #

    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!

  12. fireproofsocks
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  13. sv3
    Member
    Posted 1 year ago #

    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>

  14. olisb
    Member
    Posted 7 months ago #

    Thanks sv3 - that's the one :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic