WordPress attachment problems

Question

I use Custom Fields to set different fields I need for an interactive:

enter image description here

An interactive example can be like this:

enter image description here

enter image description here

In the last image there is an image attachment example, but I also attach videos and audios.

Then in my code I convert all info into a json as follows:

  • Interactive code:
   $attractorElements = [
    "Button"      => "ip25_button",
    "Title"       => "ip25_title",
    "Description" => "ip25_description",
    "Multimedia"  => "ip25_multimedia",
   ];

   $json['Content'] = [
      InteractiveClass::buildJsonElements("Attractor", $attractorElements),
      ...
   ];
  • InteractiveClass code:
public static function buildJsonElements($screenType, $arrayFields) {
        $arrayElements = [];
        foreach ($arrayFields as $key => $value) {
            $arrayElements[] = [
                "ID_Element" => [
                    $key => get_field($value, 'option')
                ]
            ];
        }

        return [
            "ScreenType" => $screenType,
            "Elements"   => $arrayElements
        ];
    }

This works perfectly displaying a json with all info I need (example):

{
          "ID_Element": {
            "Button 1": {
              "EN": "Button 1 English",
              "AR": "العربية",
              "media": {
                "ID": 12932,
                "id": 12932,
                "title": "mauritania",
                "filename": "mauritania-1.jpg",
                "filesize": 92850,
                "url": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                "link": "http://localhost:8080/?attachment_id=12932",
                "alt": "",
                "author": "1",
                "description": "",
                "caption": "",
                "name": "mauritania",
                "status": "inherit",
                "uploaded_to": 0,
                "date": "2020-10-30 12:03:22",
                "modified": "2020-10-30 12:03:22",
                "menu_order": 0,
                "mime_type": "image/jpeg",
                "type": "image",
                "subtype": "jpeg",
                "icon": "http://localhost:8080/wp-includes/images/media/default.png",
                "width": 512,
                "height": 512,
                "sizes": {
                  "thumbnail": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1-150x150.jpg",
                  "thumbnail-width": 150,
                  "thumbnail-height": 150,
                  "medium": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1-300x300.jpg",
                  "medium-width": 300,
                  "medium-height": 300,
                  "medium_large": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                  "medium_large-width": 512,
                  "medium_large-height": 512,
                  "large": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                  "large-width": 512,
                  "large-height": 512,
                  "1536x1536": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                  "1536x1536-width": 512,
                  "1536x1536-height": 512,
                  "2048x2048": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                  "2048x2048-width": 512,
                  "2048x2048-height": 512
                }
              }
            }
          }
        },

         ......

My question is… What’s behind in WP that sometimes makes to display an element attached like this:

{
          "ID_Element": {
            "Button 1": {
              "EN": "Button 1 English",
              "AR": "العربية",
              "media": {
                "ID": 12932,
                "id": 12932,
                "title": "mauritania",
                "filename": "mauritania-1.jpg",
                "filesize": 92850,
                "url": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                "link": "http://localhost:8080/?attachment_id=12932",
                "alt": "",
                "author": "1",
                "description": "",
                "caption": "",
                "name": "mauritania",
                "status": "inherit",
                "uploaded_to": 0,
                "date": "2020-10-30 12:03:22",
                "modified": "2020-10-30 12:03:22",
                "menu_order": 0,
                "mime_type": "image/jpeg",
                "type": "image",
                "subtype": "jpeg",
                "icon": "http://localhost:8080/wp-includes/images/media/default.png",
                "width": 512,
                "height": 512,
                "sizes": {
                  "thumbnail": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1-150x150.jpg",
                  "thumbnail-width": 150,
                  "thumbnail-height": 150,
                  "medium": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1-300x300.jpg",
                  "medium-width": 300,
                  "medium-height": 300,
                  "medium_large": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                  "medium_large-width": 512,
                  "medium_large-height": 512,
                  "large": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                  "large-width": 512,
                  "large-height": 512,
                  "1536x1536": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                  "1536x1536-width": 512,
                  "1536x1536-height": 512,
                  "2048x2048": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                  "2048x2048-width": 512,
                  "2048x2048-height": 512
                }
              }
            }
          }
        },

And other times display a simpler info (notice same image attached, but in different place)?:

 {
          "ID_Element": {
            "Button 2": {
              "EN": "Button 2 English",
              "AR": "العربية",
              "media": 12932
            }
          }
        },

Button 1 and Button 2 have the same structure in the Custom Field.

Please, anyone that could give me a hint? I would like to display the more complete info.

0
Ber Tsacianegu del Tepuy 2 months 0 Answers 7 views 0

Leave an answer