Forum Replies Created
-
AuthorPosts
-
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! 🙂
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').
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.
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?
JasonKeymasterHey guys!
Sorry for the long delay. I volunteer contribute and work has been very busy for me. Fortunately these warnings should not actually cause any real bugs and I’m assuming you don’t have WP_DEBUG_DISPLAY true on production.
I’ve fixed the non-numeric error, but I can’t reproduce the Piklist_WordPress::where() warning that @bubdev reported. I installed the plugin you mentioned but I’m not seeing anything. I am looking from the version that is going to be released next week, so it’s possible the problem was resolved in another patch.
As you can see in this other thread, a new version will be out next week which includes a number of fixes including this one. Please test it out and let us know if you find any other PHP 7.x related issues!
Happy coding!
JasonKeymasterGot it. Thanks! I haven’t tested on PHP 7.1 yet, but I will.
JasonKeymasterHi @bubdev!
Interesting. We’ve made a ticket for this. What version of Piklist are you running, please?
JasonKeymasterHi @Juan!
It sure is! Just like this:
piklist('field', array( 'type' => 'select', 'field' => 'staff_member', 'label' => 'Add Staff Members', 'columns' => 12, 'value' => '', 'add_more' => true, 'choices' => array('' => 'Select one post...') + piklist(get_posts(array( 'post_type' => 'staff', 'numberposts' => -1 )), array('ID', 'post_title')) ));Notice two things here: First, I added a
'value' => ''line that tells Piklist what the default value of the field is when there’s no value saved, yet. Second, I added thearray('' => 'Select one post...') +line. This adds an option to the beginning of the choices with a stored value of nothing, while displaying ‘Select one post…’Hope this helps! 🙂
JasonKeymasterHey @hozefasmile!
For the CSS and JS you’ll want to look into the wp_enqueue_script and wp_enqueue_style WordPress functions. You could just add them to your field, but that would mean every time your field is used they’re being added again, which isn’t terribly efficient.
Otherwise, just add the HTML to the file as you normally would. I don’t recommend adding other
piklist('field')calls in a field, as that can have unexpected results. Instead, keep it down to HTML. Here’s a field I made for using the flatpickr js plugin:<?php $id = piklist_form::get_field_id($arguments); $name = piklist_form::get_field_name($arguments); $value = is_array($value) ? esc_attr(end($value)) : esc_attr($value); $attributes['class'][] = 'flatpickr'; $attributes = piklist_form::attributes_to_string($attributes); $options = wp_parse_args(isset($options) ? $options: array(), array( 'show_time' => true, 'display_format' => false )); $show_time = $options['show_time'] ? 'data-enable-time="true"' : ''; $alt_format = $options['display_format'] ? "data-alt-input='true' data-alt-format='{$options['display_format']}'" : ''; echo <<<HTML <input type="text" id="$id" name="$name" $attributes value="$value" $show_time $alt_format placeholder="Pick date" data-input> HTML;A couple things to note in here:
- Make sure to include the
piklist_form::get_field_id($arguments),piklist_form::get_field_name($arguments), andpiklist_form::attributes_to_string($attributes)functions. As you might imagine, those will give you the field ID, name, and additional attributes, respectively, which are important to input fields in basic HTML. - A few variables are automatically injected into every field. Namely,
$arguments,$attributes, and$value.$argumentscontains all the parameters passed to the field, which you don’t usually need as the keys of the array used in thepiklist('field', array())are injected into the function where the key is the variable (such as attributes).$attributesare all the built-in and passed attributes, as you might expect, which you can extend in the way you see me doing above. And lastly,$valueis the current value of the field, whether default or what’s been saved.
Hope this helps! 🙂
JasonKeymasterHi @hozefasmile!
Just to throw it in there, you can often times accomplish these sorts of things with the custom fields. The plugin you provided, for example, you could simply add some js which targets a ion-range-slider class via normal WP enqueueing, then do something like the following:
piklist('field', array( 'type' => 'text', 'field' => 'my_range', 'attributes'=> array( 'class' => 'ion-range-slider', 'data-min' => 1, 'data-max' => 10 ) ));The plugin just wants a typical text input as its base, which is exactly what that field generates. You can, of course, create a custom field for this, but I just wanted you to know your options. 🙂
JasonKeymasterHi @xeiter!
I believe I understand that you’re hoping to have sub-directories for say, meta-boxes. So you’d have /parts/meta-boxes/feature/ and /parts/meta-boxes/foo/ as hypothetical directories. If that’s the case, then unfortunately Piklist doesn’t recursively navigate sub-directories out-of-the-box. You could, however, use hooks in the
piklist::process_partsmethod to make this possible. In fact you’d probably end up using those hooks anyway to enable/disable parts (i.e. meta-boxes, terms, settings, etc.) on your own terms.Hope this helps! 🙂
JasonKeymasterHi @deprela!
Sure! It’s just normal PHP so you can set choices to be whatever you need. You can use get_posts, wp_get_post_terms, or any other function to get the values and then set them as the choices (where the key is the value stored in the database and the value is the label presented to the user). You can even use the piklist function to pluck the values from collections:
piklist('field', array( 'type' => 'select', 'field' => 'related_post', 'label' => 'Related Post', 'choices' => piklist(get_posts(array( 'post_type' => 'post', 'numberposts' => -1 )), array('ID', 'post_title')) ));Hope this helps!
JasonKeymasterHi @ssuess!
Welcome to Piklist!
Groups are the recommended way of creating a collection of field data. You simply pull the group field and, voilà , you have all the associated data. If it’s an Add More, then you can be sure the data is paired together correctly.
A fun fact, however, is that it is possible to make a group field, but then not provide a
'field'attribute to the group. What that does is stores all the child fields separately, as if they were individual. You can even make this an add_more and the meta will be stored in the right order so the index is correct for the related fields.The only time it really makes sense to store associated data separately is if you intend on doing queries based on the value of individual meta. Say, for example, you had an address group, but you wanted to be able to pull in your posts limited to a specific country, then you’d want to store them separately. Otherwise you’d have to search within the serialized data in the query, which is rather suboptimal.
Hope this helps! 🙂
JasonKeymasterAh, I see what you’re saying now. Is the request to the external API happening server-side (PHP) or on the front-end (JS)?
JasonKeymasterHey Adam!
Glad that fixed it! Sorry for the bug in the demo code, I’ll get that fixed immediately! Thanks for pointing that out!
- Make sure to include the
-
AuthorPosts