Viewing 9 reply threads
  • Author
    Posts
    • #3944
      sancreative
      Member

      I’ve created a grouped field in a settings page
      something similar to this:

      piklist('field', array(
          'type' => 'group'
          ,'label' => 'Headings'
          ,'field' => 'global_headings_style_group'
          ,'list' => false
          ,'description' => 'Set the Template Layout Options'
          ,'fields' => array(
          
          array(
            'type' => 'text'
            ,'field' => 'global_custom_h1'
            ,'label' => 'H1 Size'
            ,'description' => 'class="regular-text"'
            ,'help' => 'You can easily add tooltips to your fields with the help parameter.'
            ,'columns' => 2
            )
      
          ,array(
          'type' => 'text'
          ,'field' => 'global_custom_h2'
          ,'label' => 'H2 Size'
          ,'description' => 'class="regular-text"'
          ,'help' => 'You can easily add tooltips to your fields with the help parameter.'
          ,'columns' => 2
           )
      
          
      
            
        )
      
      ));
      

      what is the easiest way to display on frontend?

    • #3946
      sancreative
      Member

      It would be easier if i could just display them without having to group the fields to get them to show.

      but whenever I ungroup the fields it will only display the last ‘ungrouped’ group
      not sure if this is a bug or if there is a way around this – ive tried absolutely everything with the options to get them to show.

    • #3947
      Steve
      Keymaster

      You can remove 'field' => 'global_headings_style_group', if you want and the other fields will save as normal. Let us know if that works for you.

    • #3948
      sancreative
      Member

      It works if I only want one ungrouped group on one settings page
      if i add two to the same page it renders the 2nd and not the 1st.

         piklist('field', array(
          'type' => 'group'
          ,'label' => '1st'
          ,'description' => 'An Un-grouped field. Data is saved as individual meta and is searchable.'
          ,'fields' => array(
            array(
            'type' => 'text'
            ,'field' => 'custom_h1'
            ,'label' => 'H1 Size'
            ,'description' => 'class="regular-text"'
            ,'help' => 'You can easily add tooltips to your fields with the help parameter.'
            ,'columns' => 2
            )
          ,array(
          'type' => 'text'
          ,'field' => 'custom_h2'
          ,'label' => 'H2 Size'
          ,'description' => 'class="regular-text"'
          ,'help' => 'You can easily add tooltips to your fields with the help parameter.'
          ,'columns' => 2
           )
          ,array(
          'type' => 'text'
          ,'field' => 'custom_h3'
          ,'label' => 'H3 Size'
          ,'description' => 'class="regular-text"'
          ,'help' => 'You can easily add tooltips to your fields with the help parameter.'
          ,'columns' => 2
            )
          ,array(
          'type' => 'text'
          ,'field' => 'custom_h4'
          ,'label' => 'H4 Size'
          ,'description' => 'class="regular-text"'
          ,'help' => 'You can easily add tooltips to your fields with the help parameter.'
          ,'columns' => 2
           )
          ,array(
          'type' => 'text'
          ,'field' => 'custom_h5'
          ,'label' => 'H5 Size'
          ,'description' => 'class="regular-text"'
          ,'help' => 'You can easily add tooltips to your fields with the help parameter.'
          ,'columns' => 2
          )
          )
        ));
        
           piklist('field', array(
          'type' => 'group'
          ,'label' => '2nd'
          ,'description' => 'An Un-grouped field. Data is saved as individual meta and is searchable.'
          ,'fields' => array(
            array(
            'type' => 'text'
            ,'field' => 'custom_h1'
            ,'label' => 'H1 Size'
            ,'description' => 'class="regular-text"'
            ,'help' => 'You can easily add tooltips to your fields with the help parameter.'
            ,'columns' => 2
            )
          ,array(
          'type' => 'text'
          ,'field' => 'custom_h2'
          ,'label' => 'H2 Size'
          ,'description' => 'class="regular-text"'
          ,'help' => 'You can easily add tooltips to your fields with the help parameter.'
          ,'columns' => 2
           )
          ,array(
          'type' => 'text'
          ,'field' => 'custom_h3'
          ,'label' => 'H3 Size'
          ,'description' => 'class="regular-text"'
          ,'help' => 'You can easily add tooltips to your fields with the help parameter.'
          ,'columns' => 2
            )
          ,array(
          'type' => 'text'
          ,'field' => 'custom_h4'
          ,'label' => 'H4 Size'
          ,'description' => 'class="regular-text"'
          ,'help' => 'You can easily add tooltips to your fields with the help parameter.'
          ,'columns' => 2
           )
          ,array(
          'type' => 'text'
          ,'field' => 'custom_h5'
          ,'label' => 'H5 Size'
          ,'description' => 'class="regular-text"'
          ,'help' => 'You can easily add tooltips to your fields with the help parameter.'
          ,'columns' => 2
          )
          )
        ));
    • #3949
      Steve
      Keymaster

      That’s because the field names in the two groups are the same. This is not a Piklist requirement, this is a requirement of standard forms.

      Make sure each field name is unique, and it should work fine.

    • #3950
      sancreative
      Member

      Sorry my fault for pasting the previous code in a hurry.

      I’ve tried this in a brand new install using the latest version of piklist and the demo’s enabled.
      the code i used is a modified version of piklist-demo group tab in settings
      please let me know if this works for you?

      <?php
      /*
      Title: Field Groups
      Setting: piklist_demo_fields
      Tab: Groups
      Tab Order: 40
      Order: 30
      */
      
        
        piklist('field', array(
          'type' => 'group'
          ,'label' => '1st Address (Un-Grouped)'
          ,'description' => 'An Un-grouped field. Data is saved as individual meta and is searchable.'
          ,'fields' => array(
            array(
              'type' => 'text'
              ,'field' => 'ungrouped_address_1'
              ,'label' => '1st Street Address'
              ,'columns' => 12
            )
            ,array(
              'type' => 'text'
              ,'field' => 'ungrouped_address_2'
              ,'label' => 'PO Box, Suite, etc.'
              ,'columns' => 12
            )
          )
        ));
      
          piklist('field', array(
          'type' => 'group'
          ,'label' => '2nd Address (Un-Grouped)'
          ,'description' => 'An Un-grouped field. Data is saved as individual meta and is searchable.'
          ,'fields' => array(
            array(
              'type' => 'text'
              ,'field' => 'new_ungrouped_address_1'
              ,'label' => '2nd Street Address'
              ,'columns' => 12
            )
            ,array(
              'type' => 'text'
              ,'field' => '2nd new_ungrouped_address_2'
              ,'label' => 'PO Box, Suite, etc.'
              ,'columns' => 12
            )
          )
        ));
      
        piklist('shared/code-locater', array(
          'location' => __FILE__
          ,'type' => 'Meta Box'
        ));
        
      ?>
    • #3951
      sancreative
      Member

      sorry another typo correct code below

      <?php
      /*
      Title: Field Groups
      Setting: piklist_demo_fields
      Tab: Groups
      Tab Order: 40
      Order: 30
      */
      
        
        piklist('field', array(
          'type' => 'group'
          ,'label' => '1st Address (Un-Grouped)'
          ,'description' => 'An Un-grouped field. Data is saved as individual meta and is searchable.'
          ,'fields' => array(
            array(
              'type' => 'text'
              ,'field' => 'ungrouped_address_1'
              ,'label' => '1st Street Address'
              ,'columns' => 12
            )
            ,array(
              'type' => 'text'
              ,'field' => 'ungrouped_address_2'
              ,'label' => 'PO Box, Suite, etc.'
              ,'columns' => 12
            )
          )
        ));
      
          piklist('field', array(
          'type' => 'group'
          ,'label' => '2nd Address (Un-Grouped)'
          ,'description' => 'An Un-grouped field. Data is saved as individual meta and is searchable.'
          ,'fields' => array(
            array(
              'type' => 'text'
              ,'field' => 'new_ungrouped_address_1'
              ,'label' => '2nd Street Address'
              ,'columns' => 12
            )
            ,array(
              'type' => 'text'
              ,'field' => 'new_ungrouped_address_2'
              ,'label' => '2nd PO Box, Suite, etc.'
              ,'columns' => 12
            )
          )
        ));
      
        piklist('shared/code-locater', array(
          'location' => __FILE__
          ,'type' => 'Meta Box'
        ));
        
      ?>
    • #3952
      Steve
      Keymaster

      Yup… that’s a bug!

      Try this:

      $options = get_option('piklist_demo_fields');
      
      echo _('1st Street Address: ') . $options['global_headings_style_group']['ungrouped_address_1'][0] . '
      '; echo _('PO Box, Suite, etc.: ') . $options['global_headings_style_group']['ungrouped_address_2'][0]; piklist('field', array( 'type' => 'group' ,'field' => 'global_headings_style_group' ,'label' => '1st Address (Un-Grouped)' ,'description' => 'An Un-grouped field. Data is saved as individual meta and is searchable.' ,'fields' => array( array( 'type' => 'text' ,'field' => 'ungrouped_address_1' ,'label' => '1st Street Address' ,'columns' => 12 ) ,array( 'type' => 'text' ,'field' => 'ungrouped_address_2' ,'label' => 'PO Box, Suite, etc.' ,'columns' => 12 ) ) )); piklist('field', array( 'type' => 'group' ,'field' => 'global_headings_style_group_2' ,'label' => '2nd Address (Un-Grouped)' ,'description' => 'An Un-grouped field. Data is saved as individual meta and is searchable.' ,'fields' => array( array( 'type' => 'text' ,'field' => 'new_ungrouped_address_1' ,'label' => '2nd Street Address' ,'columns' => 12 ) ,array( 'type' => 'text' ,'field' => 'new_ungrouped_address_2' ,'label' => '2nd PO Box, Suite, etc.' ,'columns' => 12 ) ) ));
    • #3953
      sancreative
      Member

      This works:

      $options = get_option('piklist_demo_fields');
      
      echo _('1st Street Address: ') . $options['global_headings_style_group']['ungrouped_address_1'][0] . '
      ';
      echo _('PO Box, Suite, etc.: ') . $options['global_headings_style_group']['ungrouped_address_2'][0];

      Thank you for your help Steve, Much appreciated.

    • #3956
      Steve
      Keymaster

      You’re very welcome. Closing ticket.

Viewing 9 reply threads
  • The topic ‘How to get value from settings page grouped fields’ is closed to new replies.