Tagged: 

Viewing 3 reply threads
  • Author
    Posts
    • #3119
      coreyhunt
      Member

      Using the data generated from the code that follows I am attempting to have an output that reads “10” x 10″, or whatever the dimensions are. When I attempt to use “get_post_meta” on the theme side, it reads “Array” no matter what I try.
      I’ve tried foreach, I’ve tried assigning it to a var and then retrieving it using the its place in the array “$dimensions[0].” Any help would be greatly appreciated.

      piklist('field', array(
          'type' => 'group'
          ,'scope' => 'post_meta'
          ,'field' => 'dimensions'
          ,'label' => 'Artwork Dimensions'
          ,'list' => false
          ,'description' => 'Enter the dimensions of the artwork.'
          ,'value' => 'Default text'
          ,'help' => 'In inches.'
          ,'fields' => array(
             array(
              'type' => 'text'
              ,'field' => 'work-length'
              ,'label' => 'Length'
              ,'columns' => 3
              ,'attributes' => array(
                'placeholder' => '0'
              )
            )
      
            ,array(
              'type' => 'text'
              ,'field' => 'work-height'
              ,'label' => 'Height'
              ,'columns' => 3
              ,'attributes' => array(
                'placeholder' => '0'
              )
            )
      
          )
       
        ));
      

      What I’ve tried on the theme side.

      $dim_vals = get_post_meta($post->ID, 'dimensions', false);
      foreach ( $dim_vals as $dim_val ) { echo $dim_val; }

      and I’ve tried.

      $dim_vals = get_post_meta($post->ID, 'dimensions', true);
      echo $dim_vals[0];

      and this.

      echo get_post_meta($post->ID, 'dimensions', true)

    • #3120
      Steve
      Keymaster

      @coreyhunt– Welcome to the Piklist community!

      For simple group fields, like yours, you don’t have to assign the group field, to an actual field (i.e. dimensions). If you remove ,'field' => 'dimensions', the other two fields will just save as normal meta data and can be retrieved like this:

      $work_length = get_post_meta($post->ID, 'work-length', true);
      
      echo $work_length;
      

      Also, 99.9% of the time you should not define scope, and just let Piklist automatically set it.

      You new code would look like this:

      piklist('field', array(
        'type' => 'group'
        ,'label' => 'Artwork Dimensions'
        ,'list' => false
        ,'description' => 'Enter the dimensions of the artwork.'
        ,'value' => 'Default text'
        ,'help' => 'In inches.'
        ,'fields' => array(
           array(
            'type' => 'text'
            ,'field' => 'work-length'
            ,'label' => 'Length'
            ,'columns' => 3
            ,'attributes' => array(
              'placeholder' => '0'
            )
          )
      
          ,array(
            'type' => 'text'
            ,'field' => 'work-height'
            ,'label' => 'Height'
            ,'columns' => 3
            ,'attributes' => array(
              'placeholder' => '0'
            )
          )
      
        )
      ));
      

      Let us know if this works for you.

      • #8689
        Anthony
        Member

        I did something similar but using field groups inside my settings page such as:

          piklist('field', array(
            'type' => 'group'
            ,'columns' => 4
            ,'field' => 'social_identities'
            ,'label' => __('Connected Accounts', 'piklist-demo')
            ,'list' => false
            ,'description' => __('Please include your account or usernames for any social identity or platform you utilize.', 'piklist-demo')
            ,'fields' => array( 
        
        array(
          'type' => 'text'
          ,'field' => 'setting_facebook_user_id'
           ,'columns' => 6
         ,'label' => 'Facebook® User ID'
         // ,'description' => 'Field Description'
         // ,'help' => 'This is help text.'
         // ,'value' => 'Default text'
          ,'attributes' => array(
          'class' => 'text'
          )
         ) 
         
         
        , array(
          'type' => 'text'
          ,'field' => 'setting_facebook_id'
           ,'columns' => 6
         ,'label' => 'Facebook® ID'
         // ,'description' => 'Field Description'
         // ,'help' => 'This is help text.'
         // ,'value' => 'Default text'
          ,'attributes' => array(
          'class' => 'text'
          )
         )
        	    
        

        However when I tried to retrieve it using it on the frontend such as:

        
        <?php 
        		
        	$theme_options = get_option('my_theme_settings');
        
          $text_field = $theme_options['setting_facebook_user_id'];
        
          echo $text_field ;
        		
        	?>
        

        It doesn’t retrieve the a value. This is not an exact example of what I am trying to do which is to get images from a field group.

        
          piklist('field', array(
            'type' => 'group'
            ,'field' => 'sitewide_defaults'
            ,'label' => __('Home Page Banner', 'piklist-demo')
            ,'list' => false
            ,'description' => __('Select the images you want appearing on your frontpage banner. Please use images that are at least 1600 x 700', 'piklist-demo')
            ,'fields' => array( 
        	    
        
        array(
            'type' => 'file'
            ,'field' => 'homepage_banner_images'
             ,'columns' => 6
            ,'label' => __('Select Primary Images', 'piklist-demo')
             ,'description' => __('Try to limit your images to 4 to assure prompt page loads. More images will slow down homepage load which is bad for SEO', 'piklist-demo')
            ,'options' => array(
              'modal_title' => __('Add File(s)', 'piklist-demo')
              ,'button' => __('Add', 'piklist-demo')
            )
          )
        
        

        I don’t know how to retrieve its values. I don’t see examples where field groups are used in the settings page. I use it to keep track of a variety of different site wide settings. I hope this is possible.

      • #8690
        Steve
        Keymaster

        Hi Anthony– The data is field groups is saved to an array.

        Try typing this after $theme_options = get_option('my_theme_settings'); :

        piklist::pre($theme_options);

        You should see the array. Now you need to loop through it like any other WordPress/PHP array.

        Hope that helps.

      • #8693
        Anthony
        Member

        That helped. There’s a stray : in your answer after ('my_theme_settings')

        Once I figured that out I could see the array. Pardon my ignorance (cause I have plenty of it) but can you provide me a link to a case where I was processing this array. I am used to the post object array but don’t have a foothold on getting this with a custom array such as this. I know … I am freakin’ newbie. Anything helps. Thanks for the help so far.

      • #8694
        Steve
        Keymaster

        copy and paste the array here: https://gist.github.com/

        give me the url when done.

    • #3122
      coreyhunt
      Member

      Steve,

      That worked beautifully. I really appreciate such a quick reply.
      I literally just discovered Piklist yesterday and so far I am really impressed.

    • #3123
      Steve
      Keymaster

      @coreyhunt– Glad you love it! Please use the Demos as a guide. You can literally copy and paste the code into your own projects.

      If you have the time we would really appreciate a 5 Star review on WordPress.org… tell them how impressed you are. It really helps keep the project going.

Viewing 3 reply threads
  • The topic ‘Retrieving Data from a Group’ is closed to new replies.