Support Forum
Support › MB Frontend Submission › Getting file linkResolved
Hi, I don't understand this documentation: https://docs.metabox.io/fields/file/
I am trying to just get the file URL from the array, but I haven't managed to. It would be really helpful if on the documentation you could include how to do it with a shortcode. Because then those using page builders can see very clearly how to adapt for their use case. I think my issue is that I don't understand arrays. Where am I going wrong?
add_shortcode( 'uploaded_paper_link', function () {
$id = get_queried_object_id();
$uploaded_files = rwmb_get_value( 'academicpdf', ['attribute' => 'url'], $id );
foreach ( $uploaded_files as $uploaded_file );
return $uploaded_file;
});
Hi Yasmine,
Can you please share the code that creates the field pdf
? Is it a subfield in a cloneable group?
Hi Long,
Here it is. You ask if it is cloneable, it wasn't. Should it not be an array then? I only thought it was an array as when I tried to output directly, the link only said 'array'!
[
'name' => __( 'Upload Research Paper PDF', 'your-text-domain' ),
'id' => $prefix . 'pdf',
'type' => 'file',
'desc' => __( 'Optional<small>Upload a PDF to give readers an easy way to access your research</small>', 'your-text-domain' ),
'max_file_uploads' => 1,
'columns' => 6,
'multiple' => false,
'tab' => 'academicreference_builder',
],
Hi,
Ok, here is the sample code to output the file URL
add_shortcode( 'uploaded_paper_link', function () {
$id = get_queried_object_id();
$uploaded_files = rwmb_meta( 'academicpdf', '', $id );
$output = '';
foreach ( $uploaded_files as $uploaded_file ) {
$output .= $uploaded_file['url'] . '<br>';
}
return $output;
});
Let me know how if it helped.
Amazing. That did it, thank you!