• Resolved parakeet

    (@parakeet)


    Early migration of basic ACF field types to CMB2 is going quite well.

    But I could also do with some pointers…

    My ACF Image field with meta_key “photos” stores values as an array.
    When I specify a CMB2 field of type “file” with ID “photos”, the value appears in admin as “File: Array (Download / Remove)”.

    If I switch the definition to field type “file_list”, using the code in the docs, it shows “Replacement 146893 (Replacement / Replacement)” (ie. the image ID is in there).

    I expect it to show the actual chosen image from the Media Library there.

    Is there any easy way to leverage the values?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I think for this, I’d set up the CMB2 fields as needed, and then save some data to them. That would give you an idea of how the saved data would be laid out, so that the existing ACF data could be mapped to match

    Thread Starter parakeet

    (@parakeet)

    I’m seeing this in wp_usermeta

    user_id:
    5442
    meta_key:
    yourprefix_demo_image_id
    meta_value:
    154410
    meta_key:
    yourprefix_demo_image
    meta_value:
    https://192.168.68.107:8888/wp-content/uploads/82122-thumbnail-3.jpg

    What’s the purpose in writing two meta records?

    Even when…

    
        'options' => array(
            'url' => false, // Hide the text input for the url
        ),
    

    … the URL text is still written. Is the media ID not sufficient to get the image?

    Feels like there is a risk in using an explicit full URL… hosts can change, so could the physical location of a file for a given ID in the Media Library.

    No idea how I’m going transfer ACF’s array method of storing an image ref into CMB2’s combination of yourprefix_demo_image_id and yourprefix_demo_image URL.

    Is this a WP-native way of doing it, or quite CMB2-specific?

    Because what I think I’ve seen in CMB2 was a) a bit more of a native way of doing things and b) gets away from what I’ve seen of ACF storing duplicate rows.

    Thanks!

    • This reply was modified 2 years, 3 months ago by parakeet.
    • This reply was modified 2 years, 3 months ago by parakeet.
    • This reply was modified 2 years, 3 months ago by parakeet.
    • This reply was modified 2 years, 3 months ago by parakeet.
    • This reply was modified 2 years, 3 months ago by parakeet.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    One would be the attachment ID, the other would be the url. It’s more convenience than anything. If you need to do something that required the ID, there it is, otherwise you get the string.

    Can’t say I’m that worried about broken urls during migrations, but I also know which tools I use most when updating URLs and it’s not just find/replace on sql dumps.

    Also I’d argue that you don’t NEED to fill both ID and URL if you don’t want to, I don’t think you’d necessarily break anything, especially with them being separate fields.

    Thread Starter parakeet

    (@parakeet)

    Yeah, I ask because, as I understand it, if you have the media ID, you can get the URL that way – and it’s probably better to.

    Can I *stop* CMB2 from writing the URL field, so that it only saved the media ID?

    Because I used the option to hide the URL field, but, if I remember correctly, it still actually saved the URL to the database.

    This would save on database records.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    It’s likely part not breaking backwards compatibility, and part fixing an issue of some sort.

    I don’t know on if you can stop, I’ve never looked into that or attempted.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Image field (ACF) to File field (CMB2)’ is closed to new replies.