Tagged: display attachments, file
- This topic has 3 replies, 2 voices, and was last updated 7 years, 6 months ago by
zanedickens.
-
AuthorPosts
-
-
August 4, 2014 at 8:38 pm #2141
zanedickensMemberHi All,
I’m trying to display all files attached to a CPT using:
$attachments = get_attached_media( '', $post->ID ); foreach ($attachment as $file) { echo '<a href="' . wp_get_attachment_url($file->ID) . '">File</a>'; }I’m trying to display this in a metabox in the admin. The following works just fine:
$file_ids = get_post_meta($post_id, 'skills_question_9'); echo '<ol>'; foreach ($file_ids as $file) { $upload = get_post($file); $title = $upload->post_title; echo '<li><a href="' . wp_get_attachment_url($upload->ID) . '">' . $title . ' </a></li>'; } echo '</ol>';But I’m trying to create something that will work on all Custom Post Types so that this metabox can be shown on all and will simply list the files and link to them so that a reviewer can see supporting documents.
Any help will be greatly appreciated!
Thanks in advance,
Z -
August 4, 2014 at 9:38 pm #2143
SteveKeymaster@zanedickens– You can use the piklist_add_part filter. The doc actually has an example for your use case.
-
August 4, 2014 at 10:14 pm #2144
zanedickensMemberHi Steve,
I’m not sure if I am missing something (working through the night so hardly sharp at the moment). I get how I can use that to get the metabox to be on all post types. I was presently using a list in the comment area to do the same, although not specifying a post type and setting it to side had my scorecard appear on all as well.
But the problem I’m having is getting the files to display without using Post Meta. Post Meta seems to necessitate the naming of the Meta key, while going for attachments sidesteps it only that it doesn’t pull / display anything at all.
Funnily enough I used something similar to the pikilist_add_part example to show the number of posts per post type.
I’ll keep reading and see if I can work out how to apply the filter to my use case.
Thanks again,
Z -
August 4, 2014 at 11:09 pm #2145
zanedickensMemberWould be pretty sweet if when locking fields Piklist displayed the linked filename instead of the Attachment ID – something for a future build? 🙂
-
-
AuthorPosts
- You must be logged in to reply to this topic.