• Resolved kemalkautsar

    (@kemalkautsar)


    Hi Guys,

    Adam helped me out to show the latest submitted form into a shortcode on another thread (https://www.ads-software.com/support/topic/showing-a-single-field-of-the-latest-entry-using-a-shortcode/#post-17554253)

    Now, what I’m trying to do is showing an image using the same kind of shortcode, but I’m having a trouble to achieve that.

    I added an Image upload field, I tried the code Adam gave me on the other thread and refer it to the Image-1 field. But it doesn’t work. I tried to var_dump(?) the data: it says like this:

    ["upload-1"]=> array(2) { 
        ["id"]=> string(3) "307" 
        ["value"]=> array(1) {
             ["file"]=> array(5) { 
                ["success"]=> bool(true) 
                ["file_name"]=> string(63) "image.jpg" 
                ["file_url"]=> string(173) "https://websitename/filepath/to/image.jpg" 
                ["message"]=> string(0) "" 
                ["file_path"]=> string(175) "filepath/to/the/hosting/image.jpg" 
           } 
        } 
    }

    Now, I want to get the URL on that Array, the [“file_url”]=> string(173) “https://websitename/filepath/to/image.jpg” section

    The code Adam gave me that I modified is like this (it doesn’t work, only gave me a result of “value”):

    add_shortcode( 'image1-last-entry', 'wpmu_shortcode_forminator_last_entry_field_image1' );
    function wpmu_shortcode_forminator_last_entry_field_image1( $atts ) { 
    
    	$a = shortcode_atts( array(
    		'form_id' => 7266,
    		'field' => 'upload-1',
    	), $atts );
    
    		
    	$entry = Forminator_Form_Entry_Model::get_latest_entry_by_form_id( $a['form_id'] );
    	
    	if ($entry) { 
    		//this is where i think i did wrong
    		$html = $entry->meta_data[$a['field']][['value']['file']];
    		
    		if ($html) {
    
    			return $html;
    			
    		}
    	
    	}
    

    Expand

    Now, my question is: how do i get the value of “file_url” inside the array inside array(?). I just need the return value of “https://websitename/filepath/to/image.jpg”

    It might seem trivial for the other programmers but it keep bugging me out for a few days now.

    thank you very much!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Dmytro – WPMU DEV Support

    (@wpmudevsupport16)

    Hello @kemalkautsar,

    I hope you’re doing great today!

    It looks like you’ll need to tweak this line a bit further:
    $html = $entry->meta_data[$a['field']][['value']['file']];

    Please try changing it to:
    $html = $entry->meta_data[$a['field']]['value']['file']['file_url'];

    Hope this helps. Please let us know if there’s still any issue.

    Best Regards,
    Dmytro

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @kemalkautsar ,

    I will mark this topic as resolved since we haven’t heard back from you for a week now.

    Let us know if you need further assistance.

    kind regards,
    Kasia

    Thread Starter kemalkautsar

    (@kemalkautsar)

    Hi Kasia and Dmytrio. Thanks it’s solved now.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Getting The URL of an Uploaded Image’ is closed to new replies.