Forum Replies Created

Viewing 15 posts - 46 through 60 (of 330 total)
  • Author
    Posts
  • in reply to: Unique Value in Term Meta #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! 🙂

    in reply to: Unique Value in Term Meta #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').

    in reply to: Unique Value in Term Meta #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.

    in reply to: Unique Value in Term Meta #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?

    in reply to: PHP 7.1 Error #7857
    Jason
    Keymaster

    Hey 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!

    in reply to: PHP 7.1 Error #7668
    Jason
    Keymaster

    Got it. Thanks! I haven’t tested on PHP 7.1 yet, but I will.

    in reply to: PHP 7.1 Error #7666
    Jason
    Keymaster

    Hi @bubdev!

    Interesting. We’ve made a ticket for this. What version of Piklist are you running, please?

    in reply to: Creating dynamic select #7664
    Jason
    Keymaster

    Hi @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 the array('' => '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! 🙂

    in reply to: How to create my own custom field #7638
    Jason
    Keymaster

    Hey @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), and piklist_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. $arguments contains all the parameters passed to the field, which you don’t usually need as the keys of the array used in the piklist('field', array()) are injected into the function where the key is the variable (such as attributes). $attributes are 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, $value is the current value of the field, whether default or what’s been saved.

    Hope this helps! 🙂

    in reply to: How to create my own custom field #7634
    Jason
    Keymaster

    Hi @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. 🙂

    in reply to: Multiple "parts" directory in one plugin #7596
    Jason
    Keymaster

    Hi @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_parts method 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! 🙂

    in reply to: Creating dynamic select #7585
    Jason
    Keymaster

    Hi @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!

    in reply to: Grouped vs not grouped #7566
    Jason
    Keymaster

    Hi @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! 🙂

    in reply to: Dynamic fields/metaboxes/post types #7557
    Jason
    Keymaster

    Ah, I see what you’re saying now. Is the request to the external API happening server-side (PHP) or on the front-end (JS)?

    in reply to: Creating a CPT in a plugin – what am I doing wrong? #7553
    Jason
    Keymaster

    Hey Adam!

    Glad that fixed it! Sorry for the bug in the demo code, I’ll get that fixed immediately! Thanks for pointing that out!

Viewing 15 posts - 46 through 60 (of 330 total)