- This topic has 7 replies, 2 voices, and was last updated 4 years, 10 months ago by
friendlyfire3.
-
AuthorPosts
-
-
March 28, 2017 at 9:42 pm #7862
friendlyfire3MemberHi, 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?
-
March 29, 2017 at 3:23 pm #7863
JasonKeymasterHey @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?
-
March 29, 2017 at 3:44 pm #7864
friendlyfire3MemberYes, 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' ) )); -
March 29, 2017 at 3:49 pm #7865
JasonKeymasterTo 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.
-
March 29, 2017 at 3:51 pm #7866
JasonKeymasterTo be clear, right now you can select multiple files, it would just make one row in the database with the key
featured_media_urlper file. Then, when you retrieve this (via get_term_meta) it would be an array of values when usingget_term_meta($term, 'featured_media_ur'). -
March 29, 2017 at 3:54 pm #7867
friendlyfire3MemberI’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.
-
March 29, 2017 at 3:59 pm #7868
JasonKeymasterFor 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
urlskey. Then useget_term_meta($term_id, 'urls')to get an array of them all.Hope this helps! 🙂
-
March 29, 2017 at 5:02 pm #7869
friendlyfire3MemberSuper helpful, Jason. Close this puppy out!
-
-
AuthorPosts
- The topic ‘Unique Value in Term Meta’ is closed to new replies.