WordPress.org

Support

Support » Plugins and Hacks » Custom Content Type Manager » [Resolved] Attachment file in custom type article

[Resolved] Attachment file in custom type article

  • Hello, this plugin is great thanks,
    I want to create a simple upload field to attach pdf files to my custom type articles.
    I created a custom field “media” for uploading, set as repeatable to_array,
    in the template with the following code, recover the link to the article containing the pdf file:

    $my_array = get_custom_field('allegato:to_array');
    foreach ($my_array as $item) {
     	print "<div>";
    	print CCTM::filter($item,'to_link_href');
    	print "</div>";
    }

    I would rather the direct link to the file, and print the title of the file, how should I do?

    thanks

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

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

    @fireproofsocks

    Upload forms are hard to create — there are a lot of security concerns and the possible implementations may not work on every server. I can’t give you a straight-forward answer, but I strongly recommend that you don’t try to build your own form.

    Instead, I would recommend that you use the WP media uploader — create a “Media” field for your post-type (http://code.google.com/p/wordpress-custom-content-type-manager/wiki/Media) and then you can tie into the WP media library and upload files using the functionality that WP already supplies. That’s MUCH easier and MUCH more secure.

    thanks for your answer,
    sorry maybe I gave a bad explanation, my English is very poor!

    I had already created a custom fiel MEDIA, but do not know the code to display attachments in frontend.

    With this code:
    print CCTM::filter($item,'to_link_href');
    I make a link to the page that contains the attachment,
    instead I want to download the pdf file directly,
    and then I want to show the name of the file.

    you can write the correct code?
    thanks

    Plugin Contributor fireproofsocks

    @fireproofsocks

    Ah. I don’t know if you can control that in WordPress, to be honest: WordPress controls the “Content-Type” headers, and that’s usually what triggers a download. MODX lets you control this, but I don’t think you have any control over it in WordPress. PDFs are especially difficult because even if you try to force a download, the browser may or may not download it depending on which plugins are installed.

    Remember: you don’t need to use any of the CCTM’s output filters. They’re there for CONVENIENCE. If they don’t help you, do not use them. All you need to do is convert an attachment id to a link. You can do that using a CCTM output filter or use WordPress’s get_permalink() function.

    I tried get_permalink($item), but the result is the same to_link_href: links to the article with the attachment instead of the direct link to the pdf,
    now solved with the plugin “Attachments”, which allows you to customize and use even within the content type, but I preferred to create the attachment as a custom field.
    thanks for your suggestions

    Plugin Contributor fireproofsocks

    @fireproofsocks

    This is a variation of the question I get all. the. time. The challenge is this: convert an integer key to the data it represents. Peruse the wiki if you need to see examples of this: I’ve written about it a lot there. If you pass a POST’s id to get_permalink() then you back the POST’s data. If you pass an ATTACHMENT’s id to get_permalink() then you should get back the ATTACHMENT’s data. When in doubt, look in the database: what is that number you’re feeding to get_permalink()? Is it a post id or an attachment id? Installing other plugins will not help you if you cannot wrap your head around this fundamental tenet of the data model.

    Usually people’s heads explode here: you retrieve a post and all of its data. The post has an id, but it also is REFERENCING related posts and attachments via their ids. So you might have a custom field or a “featured image” that stores an attachment id. It’s that attachment id that you need to work with NOT the post’s id.

    In pseudo code:

    $post = $Q->get_post(123);
    get_permalink($post['ID']); // get's the POST's permalink
    get_permalink($post['my_custom_image']); // get's the ATTACHMENT's permalink
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Attachment file in custom type article’ is closed to new replies.
Skip to toolbar