Home Forums Add-ons Repeater Field Show image file-name only in admin/backend


Show image file-name only in admin/backend

  • Hi there,

    I am currently optimizing some ACF fields.

    Starting position:

    Field group 1 – image (field: profile picture)

    … should move to …

    Field group 2 – image (field: picture)

    I don’t want to play around in the database. So I have to manually re-create all entries. It would be a great help for me if I could only show the filename of the image (field: profile picture) in the admin. I don’t want to click on the image properties every time.

    For clarification please have a look at the screenshot:

    At the top you can see the new entries – Field group 2
    Below you can see the old entries. I now need the image file name. Can I have this displayed quickly?

  • @tobiasheuken

    I have a quick dirty solution for you, if I am understanding the issue correctly. Since this is just temporary, this should be an OK solution for this scenario.

    Now… I am assuming that:

    1) You have a repeater of data
    2) You don’t mind adding another field within that repeater to display the filename

    Also… my brain could have overthought this issue from the beginning. There *may* be a super simple way to accomplish this. However, it only took me a few minutes, so.. here goes:

    Step 1: Install the ACF Enhanced Message Field plugin, so that we can add a field to your repeater that allows for PHP code. Thanks Dreb Bits!

    Step 2: Add the following code into your newly created Enhanced Message Field in your repeater:

    global $my_row_number;
    if ( !$my_row_number ) { $my_row_number = 0; }
    $rows = get_field('repeater-name');
    $specific_row = $rows[$my_row_number];
    $sub_field_value = $specific_row['image-field-name'];
    echo basename($sub_field_value['url']); // echos *just* the filename for the image

    Sure, it’s a weird solution, but assuming I understand your issue correctly, it works like a charm 🙂

    Take care to change the Repeater field name, as well as the Sub field name when using the above code.

    Hope this works! Let me know.

  • Hi Keith,

    Thank you very much for your quick help.

    I put the following code in the message field:

    global $my_row_number;
    if ( !$my_row_number ) { $my_row_number = 0; }
    $rows = get_field('allgemein_mitglied');
    $specific_row = $rows[$my_row_number];
    $sub_field_value = $specific_row['allgemein_profilbild'];
    echo basename($sub_field_value['url']); // echos *just* the filename for the image

    After updating, however, the field changes to a “one-line text field”. Unfortunately, the desired effect does not work.

  • Are you using the plugin for the “Enhanced Message Field”? It’s an add-on for ACF that allows for PHP code.

  • Yes, I used this field.

    Yes, but… yes but…. after saving, the field type has changed over and over again automatically. This is not logical.

    Screen 1: Creating the field (open the screen in a new tab and zoom in)
    Screen 2: Settings after saving the fields

  • That’s weird. Can’t be sure why that is.

    I have a different approach:

    1) Create a regular text field. Make note of the ‘key’. You can expose the key by clicking Screen Options at the top right of the Edit Fields screen.

    2) Add the code below to a Custom Plugin or functions file.

    In the ‘add_filter’ line, of course, use your key from Step 1.
    You can also change ‘full’ to some other image size, to get the image filename you are after.

    function my_acf_load_value( $value, $post_id, $field ) {
      global $my_row_number;
      if ( !$my_row_number ) { $my_row_number = 0; }
      $meta_key = 'allgemein_mitglied_'.$my_row_number.'_allgemein_profilbild';
      $sub_field_value = get_post_meta( $post_id, $meta_key, true );
      $image_attributes = wp_get_attachment_image_src( $sub_field_value, 'full' );
      $value = basename( $image_attributes[0] );
      return $value;
    add_filter('acf/load_value/key=field_59c9182f21022', 'my_acf_load_value', 10, 3);
  • Handy solution that Keith.
    Works really well.

    Would there be a way of displaying that as a non-editable field?

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Show image file-name only in admin/backend’ is closed to new replies.