How to display attachemnts upload /modification date?

Support MB User Profile How to display attachemnts upload /modification date?Resolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #33569
    synchrosynchro
    Participant

    Hi, so I am having custom fields for file upload in the user profile. Now is there a way to display in the front-end the date when the file was uploaded/modified?

    I would appreciate any hint, thanks.

    #33605
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can use the WordPress function get_the_date() to get the date of files uploaded.
    For example:

    $files = rwmb_meta( 'file_upload_vd4t530xyb', ['object_type' => 'user'], 1 );
    foreach ($files as $file_id => $file_data) {
        echo get_the_date( 'c', $file_id );
    }

    Read more on the documentation
    https://docs.metabox.io/fields/file-upload/#data
    https://developer.wordpress.org/reference/functions/get_the_date/

    #33634
    synchrosynchro
    Participant

    Thank you for your answer Long.
    I tried inserting it into the view like this:

    {% set files = mb.rwmb_meta( 'dodaj-dokumenty', user ) %}
    {% for file in files %}
    {{ mb.get_the_date( 'd.m.Y' ) }}
    {% endfor %}

    but I can't get it work.
    I get an error whenever I try to modify the code and get the variables.

    And if I just insert it like this:

    {% for item in field %}
    {{ mb.get_the_date( 'd.m.Y' ) }}
    {% endfor %}

    I obviously get the page publish date.

    I would appreciate if you could help me further on this and get the code right.

    #33685
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You need to pass the file ID to the function get_the_date() to get the date of the file. If not, it will take the current post ID to get the date. The code should be:

    {% for item in user.file_upload %}
        {{ mb.get_the_date( 'd.m.Y', item.ID ) }}
    {% endfor %}
    #33697
    synchrosynchro
    Participant

    Thank you so much for help, Long. I had to make a couple of trials but eventually this is the code that worked for me:

    {% set field = attribute( user, 'dodaj-dokumenty' ) %}
            {% for item in field %}
            <a href="{{ item.url }}">{{ item.name }}</a>
            {% endfor %}
        
            {% for item in field %}
            Data: {{ mb.get_the_date( 'd.m.Y g:i:s A', item.ID ) }}
            {% endfor %}

    Thank you again, really appreciated.

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