Getting file link

Support MB Frontend Submission Getting file linkResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #38156
    YasmineYasmine
    Participant

    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;
    });
    #38160
    Long NguyenLong Nguyen
    Moderator

    Hi Yasmine,

    Can you please share the code that creates the field pdf? Is it a subfield in a cloneable group?

    #38163
    YasmineYasmine
    Participant

    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',
    ],
    #38167
    Long NguyenLong Nguyen
    Moderator

    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.

    #38185
    YasmineYasmine
    Participant

    Amazing. That did it, thank you!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.