This topic contains 3 replies, has 2 voices, and was last updated by  Steve 1 month, 1 week ago.

  • Author
    Posts
  • #9442

    shayneol
    Participant

    Hello,

    I’m still not sure what’s going on with the update script, but I found out that there’s an issue with having only a File-Upload field inside of a group, which is how mine is setup. If I add any other input field to the group, the images in the file-upload field are saved and displayed correctly. For example, if I change my code to the following and re-add the files in the file-upload field, everything saves and displays fine, but then I will have a random input field on the screen:

      piklist('field', array(
        'type' => 'group'
        ,'field' => 'featured_images'
        ,'label' => __('Featured Images For Product List Page', 'piklist-demo')
        ,'add_more' => false
        ,'template' => 'field'
        ,'fields' => array(
    
          array(
    	    'type' => 'file'
    	    ,'field' => 'images'
    	    //,'scope' => 'post_meta'
    	    ,'label' => __('Featured Images For Product List Page', 'piklist-demo')
            ,'columns' => 12
    	    ,'options' => array(
    	      'modal_title' => __('Add File', 'piklist-demo')
    	      ,'button' => __('Add', 'piklist-demo')
    	    )
          )
    
          ,array(
            'type' => 'text'
            ,'field' => 'city'
            ,'label' => __('City', 'piklist-demo')
            ,'columns' => 5
          )
    
        )
      ));

    I remember that I set this up this way because if I don’t put the file-upload field into a group, it won’t let me output all of the images onto the front-end.

    For example:
    If I just use the following code (without a group) and save multiple files in the file-upload field, it will only output the ID of the first image uploaded.

    piklist('field', array(
    	'type' => 'file'
    	,'field' => 'temp-upload'
    	,'scope' => 'post_meta'
    	,'template' => 'field'
    	,'label' => 'Media Uploader'
    	,'options' => array(
    		'modal_title' => 'Add File(s)'
    		,'button' => 'Add'
    	)
    ));
    <?php
    $temp_image = get_post_meta(get_the_ID(), 'temp-upload', true);
    ?>
    
    <pre><?php print_r($temp_image)?></pre>

    I’ve had this issue on multiple sites, so I know it’s not specific to this project alone. Thanks for your help on resolving this.

  • #9443

    Steve
    Keymaster

    I split this out into a new topic since it’s not related to the original.

    So, I’m not 100% clear on the issue, but here are two things I noticed:
    1) There’s no benefit to having one file in a group field. Just use the field.
    2) Using get_post_meta with the last parameter set to true will only return one value. Change it to false:

    get_post_meta()

  • #9450

    shayneol
    Participant

    Oh shoot! That was it. I didn’t even notice that. Thanks!!

  • #9451

    Steve
    Keymaster

    Great. Marking this resolved

The topic ‘Upload field issue’ is closed to new replies.