Custom Fields
Re-Envisioned
Support MB Settings Page Trying to pull the URL for a file upload from Settings Page using Shortcode

  • Creator
    Topic
  • #27502
    Resolved chris@m11design.com
    Participant

    I am trying to display some images in a Beaver Themer HTML module. I have settings page where the site owner can upload a logo ( and some other images ) using the File Upload field type. I have tried many things I have found here in the forum but can't seem to get it to work. Here's where I am now with the shortcode:

    <img src="[rwmb_meta id='business-info#info_business_logo' attribute='url']">

    I have also tried it without the settings page id:
    <img src="[rwmb_meta id='info_business_logo' attribute='url']">

    Can you help me figure out what I'm doing wrong? THanks so much.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Author
    Replies
  • #27506
    chris@m11design.com
    Participant

    Updating with more information:

    I decided to try and see if I could just create a view and then use the short code. I started with only using "site" fields. The only ones that would show on the front end of the site are the default "site" fields. Example: {{site.title}}

    I cannot get any of the custom fields to show up on the front end of the site. I must have made some mistake in setting this up that I don't know about or don't understand. Hoping this makes sense to someone and that you can point me in the right direction. Thanks, again.

    #27542
    Long Nguyen
    Moderator

    Hi Chris,

    The multiple setting is always set to true for the field type file_upload, which means the return of the helper function rwmb_meta() is an array so you need to loop through the array to get each element.

    Get more details in the documentation https://docs.metabox.io/fields/file-upload/#template-usage

    #27556
    chris@m11design.com
    Participant

    Thanks for the reply. Forgive my ignorance here but do I need to create a shortcode using a form of the code on the page you linked? Would one of the other upload options allow for a single file upload without using the media library uploaded? I don't want the user to see the media library in the upload process. Thanks again.

    #27588
    Long Nguyen
    Moderator

    Hi,

    No need to create a custom function, you just need to create a loop in View, see more on this topic https://metabox.io/support/topic/display-multiple-media-files-connected-to-a-user/

    {% for item in post.file_upload_id %}
        <img src="{{ item.url}}">
    {% endfor %}

    There is a file type image that works similar to file_upload, it allows the user to upload the image file without accessing the Media Library but the multiple setting also set to true for this field.

    #27595
    chris@m11design.com
    Participant

    There must be something else that I am doing wrong. I moved the site over from LocalHost to a live server but still can't get this to work.

    I created a new View and have set it up as a Type: Shortcode.

    Here's the code in the View:

    <h1>
        This is a test.
    </h1>{% set group = attribute( site, 'business-info' ) %}
    
    {% for item in group.info_business_logo %}
        {{ item.url }}
    {% endfor %}
    
    {% set group = attribute( site, 'business-info' ) %}
    
    {% for item in group.info_business_logo %}
        <a href="{{ item.url }}">{{ item.title }}</a>
    {% endfor %}
    
    {% set group = attribute( site, 'business-info' ) %}
    <img src="{{ group.single_image_zd6n6bftlti.thumbnail.url }}" width="{{ group.single_image_zd6n6bftlti.thumbnail.width }}" height="{{ group.single_image_zd6n6bftlti.thumbnail.height }}" alt="{{ group.single_image_zd6n6bftlti.thumbnail.alt }}">
    
    {% set group = attribute( site, 'business-info' ) %}
    {% for clone in group.image_upload_egw66lpdlun %}
        {% for item in clone %}
            <img src="{{ item.thumbnail.url }}" width="{{ item.thumbnail.width }}" height="{{ item.thumbnail.height }}" alt="{{ item.thumbnail.alt }}">
        {% endfor %}
    {% endfor %}

    And here's the output: https://base.m11design.dev/test-page/

    I've checked and rechecked the code and I am obviously missing something or just don't know what I'm doing. I've used Pods Framework for years and years but I just purchased MB and this is my first time using it.

    #27608
    Long Nguyen
    Moderator

    Hi,

    Please take a look at my screen record to know how to show the image from the settings page https://share.getcloudapp.com/ApuYXd8N.

    If it still troubles you, please share the code that creates the settings page and custom fields, I will help you to check.

    #27661
    chris@m11design.com
    Participant

    Thanks for your response. I fought with this for several more hours. I finally decided to just try changing the "key" for the Tab settings on each tab in my Settings Page setup. I had used numbers for those and I changed the to words. Now the fields show up using views as they are supposed to. Is that really what was wrong? I mean is the correct setup for the Key on the tabs in Settings Pages supposed to be words and not numbers?

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