Viewing 3 reply threads
  • Author
    Posts
    • #10870
      guit4eva
      Participant

      I am able to get Piklist fields to show up in the post editor, until I try add a group. Adding the group demo field straight from the documentation (without any changes):

      piklist('field', array(
          'type' => 'group'
          ,'field' => 'address_group' // removing this parameter saves all fields as separate meta
          ,'label' => __('Address (Grouped)', 'piklist-demo')
          ,'list' => false
          ,'description' => __('A grouped field with the field parameter set.', 'piklist-demo')
          ,'fields' => array(
            array(
              'type' => 'text'
              ,'field' => 'address_1'
              ,'label' => __('Street Address', 'piklist-demo')
              ,'required' => true
              ,'columns' => 12
              ,'attributes' => array(
                'placeholder' => 'Street Address'
              )
            )
            ,array(
              'type' => 'text'
              ,'field' => 'address_2'
              ,'label' => __('PO Box, Suite, etc.', 'piklist-demo')
              ,'columns' => 12
              ,'attributes' => array(
                'placeholder' => 'PO Box, Suite, etc.'
              )
            )
            ,array(
              'type' => 'text'
              ,'field' => 'city'
              ,'label' => __('City', 'piklist-demo')
              ,'columns' => 5
              ,'attributes' => array(
                'placeholder' => 'City'
              )
            )
            ,array(
              'type' => 'select'
              ,'field' => 'state'
              ,'label' => __('State', 'piklist-demo')
              ,'columns' => 4
              ,'choices' => piklist_demo_get_states()
            )
            ,array(
              'type' => 'text'
              ,'field' => 'postal_code'
              ,'label' => __('Postal Code', 'piklist-demo')
              ,'columns' => 3
              ,'attributes' => array(
                'placeholder' => 'Postal Code'
              )
            )
          )
        ));

      results in:

      There has been a critical error on your website. Please check your site admin email inbox for instructions.

      Is there something else I should be doing to get the group field to work?

    • #10876
      Steve
      Keymaster

      I tested this field and it works for me. Please enable wp_debug so WordPress can log the error message: https://wordpress.org/support/article/debugging-in-wordpress/

    • #10877
      guit4eva
      Participant

      EDIT: Oh gees…there’s the problem:

      'choices' => piklist_demo_get_states()

      in line 86. My bad! Thanks so much for the help:)

      ————————————————————
      Leaving the following here in case anyone else makes the same mistake
      ————————————————————

      This is the error that comes up:

      Fatal error: Uncaught Error: Call to undefined function piklist_demo_get_states() in /usr/www/users/beautinf/wp-content/plugins/symia-piklist/parts/meta-boxes/establishment-metabox.php:86 
      Stack trace: 
      #0 /usr/www/users/beautinf/wp-content/plugins/piklist/includes/class-piklist.php(523): include() 
      #1 /usr/www/users/beautinf/wp-content/plugins/piklist/includes/class-piklist-meta.php(319): Piklist::render('/usr/www/users/...', Array) 
      #2 /usr/www/users/beautinf/wp-admin/includes/template.php(1389): Piklist_Meta::meta_box(Object(WP_Post), Array) 
      #3 /usr/www/users/beautinf/wp-admin/edit-form-advanced.php(686): do_meta_boxes(Object(WP_Screen), 'normal', Object(WP_Post)) 
      #4 /usr/www/users/beautinf/wp-admin/post.php(206): require('/usr/www/users/...') 
      #5 {main} thrown in /usr/www/users/beautinf/wp-content/plugins/symia-piklist/parts/meta-boxes/establishment-metabox.php on line 86

      This is my /parts/meta-boxes/establishment-metabox.php file:

      <?php
      /*
      Title: Establishment Metabox
      Post Type: establishment
       */
      
      piklist('field', array(
          'type' => 'select',
          'field' => 'establishment_type',
          'label' => 'Establishment Type',
          'choices' => array(
              'guesthouse' => 'Guesthouse',
              'villa' => 'Villa',
              'cottage' => 'Cottage',
              'apartment' => 'Apartment',
          ),
      ));
      
      piklist('field', array(
          'type' => 'select',
          'field' => 'establishment_no_bedrooms',
          'label' => 'Number of Bedrooms',
          'choices' => array(
              '1_bedroom' => '1',
              '2_bedroom' => '2',
              '3_bedroom' => '3',
              '4_bedroom' => '4',
              '5_bedroom' => '5',
              '6_bedroom' => '6',
              '7_bedroom' => '7+',
          ),
      ));
      
      piklist('field', array(
          'type' => 'textarea',
          'field' => 'rates',
          'label' => 'Rates',
          'add_more' => true,
          'attributes' => array(
            'rows' => 10,
            'cols' => 50,
            'class' => 'large-text',
          )
      ));
      
      piklist('field', array(
          'type' => 'group'
          ,'field' => 'address_group' // removing this parameter saves all fields as separate meta
          ,'label' => __('Address (Grouped)', 'piklist-demo')
          ,'list' => false
          ,'description' => __('A grouped field with the field parameter set.', 'piklist-demo')
          ,'fields' => array(
            array(
              'type' => 'text'
              ,'field' => 'address_1'
              ,'label' => __('Street Address', 'piklist-demo')
              ,'required' => true
              ,'columns' => 12
              ,'attributes' => array(
                'placeholder' => 'Street Address'
              )
            )
            ,array(
              'type' => 'text'
              ,'field' => 'address_2'
              ,'label' => __('PO Box, Suite, etc.', 'piklist-demo')
              ,'columns' => 12
              ,'attributes' => array(
                'placeholder' => 'PO Box, Suite, etc.'
              )
            )
            ,array(
              'type' => 'text'
              ,'field' => 'city'
              ,'label' => __('City', 'piklist-demo')
              ,'columns' => 5
              ,'attributes' => array(
                'placeholder' => 'City'
              )
            )
            ,array(
              'type' => 'select'
              ,'field' => 'state'
              ,'label' => __('State', 'piklist-demo')
              ,'columns' => 4
              ,'choices' => piklist_demo_get_states()
            )
            ,array(
              'type' => 'text'
              ,'field' => 'postal_code'
              ,'label' => __('Postal Code', 'piklist-demo')
              ,'columns' => 3
              ,'attributes' => array(
                'placeholder' => 'Postal Code'
              )
            )
          )
        ));
    • #10878
      Steve
      Keymaster

      It looks like you copied the address_group field directly from the demos. It has a function called “piklist_demo_get_states()” in it, that you didn’t copy over. You can either remove that entire field, or replace piklist_demo_get_states() with an array of choices like:

      ,'choices' => array(
          'nj' => 'NJ',
          'nj' => 'NY'
       )
Viewing 3 reply threads
  • You must be logged in to reply to this topic.