Tagged: ,

Viewing 7 reply threads
  • Author
    Posts
    • #7862

      Hi, I love that you have term meta options https://piklist.com/learn/doc/terms/

      I searched for an answer to this but came up empty.

      I noticed when creating a meta field, for example:

      <?php
      /*
      Title: Upload Fields
      Taxonomy: random_tax
      New: true
      */
      ?>
      
      <?php
        
        piklist('field', array(
          'type' => 'file'
          ,'field' => 'featured_media'
          ,'label' => __('Featured Media', 'piklist-demo')
          ,'options' => array(
            'modal_title' => __('Add File(s)', 'piklist-demo')
            ,'button' => __('Add', 'piklist-demo')
          )
        ));
       ?>
      

      And I add a couple of images, it creates a new term meta field for each image and increments the id.

      I know that multiple values can be added to a meta field using the unique parameter on add_term_meta or update_term_meta but I’m not sure how to do this just using piklist.

      What am I missing?

    • #7863
      Jason
      Keymaster

      Hey @friendlyfire3!

      I’m sorry, I’ve read over this a couple times now and I’m still not entirely sure what you’re asking. Depending on the field Piklist will add multiple values for a key. Are you talking about serialization of multiple values into a single row?

    • #7864

      Yes, I want to add multiple values for a key. What type of field does this? And are there docs that help understand which is which?

      I’m currently using:

      
        piklist('field', array(
          'type' => 'file'
          ,'field' => 'featured_media_url'
          ,'label' => __('Featured Media Url', 'piklist-demo')
          ,'attributes' => array(
            'class' => 'regular-text'
      	   ,'readonly' => 'readonly'
          )
        ));
    • #7865
      Jason
      Keymaster

      To be clear, you want to be able to select multiple files and have it enter the database as a single, serialized array? I have to ask why you’d prefer that over just having one value per row? That’s generally the better storage method.

    • #7866
      Jason
      Keymaster

      To be clear, right now you can select multiple files, it would just make one row in the database with the key featured_media_url per file. Then, when you retrieve this (via get_term_meta) it would be an array of values when using get_term_meta($term, 'featured_media_ur').

    • #7867

      I’m actually storing urls, not ids. However, your second post makes sense. Let me play with that and get back to you.

      Thanks for the response.

    • #7868
      Jason
      Keymaster

      For something like that I would do:

      piklist('field', array(
        'type' => 'text',
        'field' => 'urls',
        'label' => 'URLs',
        'add_more' => true
      ));

      That will store each instance as a row under the urls key. Then use get_term_meta($term_id, 'urls') to get an array of them all.

      Hope this helps! 🙂

    • #7869

      Super helpful, Jason. Close this puppy out!

Viewing 7 reply threads
  • The topic ‘Unique Value in Term Meta’ is closed to new replies.