Viewing 3 reply threads
  • Author
    Posts
    • #2141
      zanedickens
      Member

      Hi 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

    • #2143
      Steve
      Keymaster

      @zanedickens– You can use the piklist_add_part filter. The doc actually has an example for your use case.

    • #2144
      zanedickens
      Member

      Hi 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

    • #2145
      zanedickens
      Member

      Would be pretty sweet if when locking fields Piklist displayed the linked filename instead of the Attachment ID – something for a future build? 🙂

Viewing 3 reply threads
  • You must be logged in to reply to this topic.