Viewing 11 reply threads
  • Author
    • #9143

      Hi, Is there anyway to to add attachments using piklist rather than adding them in the content area via the “insert Media” button in the wysiwyg?

      I don’t want to use a custom field, I want to select them via a piklist field and then store them how wordpress stores them – as attachments.

      I then want to use something like “get_attached_media( ‘image’, $post_id )” to get the attachments.

      I did try to use the code from the demo:

      However, it’s doing this weird thing where when I select three images and then publish, all three images become the first one selected.

      What am I missing?

    • #9144

      Btw, Running 0.11.4

    • #9156

      The featured image demo is the way to go. Not sure why all three images are the same. I just tested and it works fine.

      Does the featured image box work in the demos?

    • #9160

      Yes, it does. I tried it on another post type and I’m still having the same issue.

      I did notice that the demo does away with the traditional featured media box. Would that need to be done in order for it to work?

      I dug around the demo code to see how you removed it but I didn’t see anything specific. Let me know if you have any other ideas. As always, thanks for your help, Steve!

    • #9167

      Yup… You need to remove the default featured image metabox or else you are duplicating the field.

      This doc explains how to remove it:

      Just replace custom-fields with thumbnail and post with your CPT.

    • #9169

      Update: This works once I hid the featured media box:

      ,'hide_meta_box' => array(
                  /* here the Feature image div */

      The images now appear correctly. However, now I have a new issue. I can’t get them via any wp method.

      I’ve tried:

      global $post;
      $attachments = get_posts( array(
          'post_type'      => 'attachment',
          'posts_per_page' => -1,
          'post_status'    => 'any',
          'post_parent'    => $post->ID,
          'exclude'        => get_post_thumbnail_id(),
      ) );


      $attachments = get_children(array('post_parent' => $post->ID,
                              'post_status' => 'inherit',
                              'post_type' => 'attachment',
                              'post_mime_type' => 'image',
                              'order' => 'ASC',
                              'orderby' => 'menu_order ID'));

      The only thing I can get is the the post thumbnail with:

      get_post_thumbnail_id( $post->ID );

      It looks like piklist isn’t actually attaching these extra images to the custom post type or I’m missing something. Any advice is appreciated.

    • #9170

      One more update: I noticed that the following code:

      get_post_meta( $post->ID, '_thumbnail_id', false );

      gets the ids of all the attachments. That’s great and all but I am trying to avoid custom post meta to pull them. I was anticipating using native wp functions like (get_posts etc) to get the attachments because I have a frontend page builder that uses those functions to grab attachments and I don’t really want to hack into it.

      Let me know if this is possible.

    • #9171

      There is no place in the default WordPress post table to save attachment data.

    • #9172

      Ok, So there’s no way to use piklist to save attachments and use native wp methods to get those attachements?

      Also, why does the piklist demo for uploading featured images say this:

      Use this field to match WordPress featured image field name.

    • #9173

      Everything about Piklist is done the WordPress way including retrieving data. You can use the native WordPress function get_post_meta to retrieve the attachment information.

      As for matching the WP featured image field name… if you are replacing the default WordPress field, then you need to use the same field name.

    • #9174

      “Everything about Piklist is done the WordPress way including retrieving data. You can use the native WordPress function get_post_meta to retrieve the attachment information.”

      I get that (and really appreciate it!) However, I think i should rephrase that:

      Can piklist add media to a post by updating the attachment’s parent field to be the id of the post we’re attaching it to?

      For example, this is how I would do it if I was writing something custom:

      wp_update_post( array(
              'ID' => $attachment_id,
              'post_parent' => $post_id
    • #9175

      To get $attachment_id you would need to write some JS to detect the id of the image.

      Or I guess you can also save the image to the post_meta table and get the id there. You could run a filter on save_post as 9999, and pull the meta after it’s saved. Totally untested… 😉

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