Wednesday, December 28, 2022
HomeWordPress Developmentplugins - The way to save mediaupload a number of URLs as...

plugins – The way to save mediaupload a number of URLs as array meta?


I wish to add a number of photos to meta. I’m able to save single url efficiently. I’m not positive add a number of URLs to meta.

The one picture mediaupload works advantageous. under is the code for it. The a number of mediaupload works advantageous within the backend editor. I do not know save and retrieve(in php) a number of picture paths in meta. Can anybody please assist or information me in the correct path?

attributes that save the meta values for a single picture.

p_mediaURL: {
        sort: "string",
        default: "",
        meta: "_duib_p_mediaURL",
        supply: "meta",
    },
    p_mediaID: {
        sort: "integer",
        default: null,
        meta: "_duib_p_mediaID",
        supply: "meta",
        default: "",
    },

In edit operate:

    const onSelectImage = (media) => {
        setAttributes({
            p_mediaURL: media.url,
            p_mediaID: media.id,
            mediaAlt: media.alt,
        });
    };

Mediaupload element

<MediaUpload
    onSelect={onSelectImage}
    allowedTypes="picture"
    worth={p_mediaID}
    render={({ open }) => (
    <Button className="is-primary mt-3" onClick={open}>
    Open Media Library
    </Button>
    )}
/>

Mediaupload element for a number of photos that works in editor.

<MediaUpload
    onSelect={(gallery) => {
    props.setAttributes({ gallery});
    }}
    sort="picture"
    a number of
    worth={props.attributes.gallery}
    render={({ open }) => (
    <Button className="button button-large" onClick={open}>
        Choose Photos
    </Button>
    )}
/>

The register_meta operate is

operate _duib_p_addimages_register_post_meta() {
register_meta(
    'submit',
    '_duib_p_addimages',
    [
        'auth_callback' => '__return_true',
        'default'       => __( '', '_duib_p_addimages' ),
        'show_in_rest' => array(
        'schema' => array( 
            'type'  => 'array', 
            'items' => array( 
                'type' => 'integer' 
            )
        )
            ),
        'single'        => true,
        'type'          => 'string',
        'object_subtype' => 'properties',
    ]
);
}
add_action( 'init', '_duib_p_addimages_register_post_meta' );

The pattern json output is

"meta": {
 
  "_duib_p_mediaURL": "http://localhost/property/wp-content/uploads/2022/12/hele_03.jpg",
  "_duib_p_description": "",
  "_duib_p_addimages": [
    
  ]
},

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments