How to show image url with folder in all sizes from Rest API

Support MB REST API How to show image url with folder in all sizes from Rest APIResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #16391
    PTiCAPTiCA
    Participant

    I use the rest api plugin and metabox type "image_advanced". Everything works fine, I just need to display URL images in all sizes with the complete url "/folder/image.jpg".

    How do I do this?

    Thanks for advice

    rest api sizes

    #16412
    Anh TranAnh Tran
    Keymaster

    Hi,

    You should transform the data from the REST response. Here is the example:

    $data = your_function_to_get_data_from_REST();
    $file = $data['file'];
    $folder = str_replace( basename( $file ), '', $file );
    $sizes = $data['sizes'];
    foreach ( $sizes as &$size ) {
        $size['file'] = $folder . $size['file'];
    }
    var_dump( $sizes ); // Now you have folder in your URL
    #17460
    PTiCAPTiCA
    Participant

    Thanks for the report but I don't know how to use this example.
    I am not a PHP programmer and I need an example that I just put into function.php and rest api will return complete image addresses.

    Thanx

    #17859
    CaballeroCaballero
    Participant

    Hi!
    This workaround is pretty long.
    Now we use

    $bg = rwmb_meta( 'advantages_bg', array( 'size' => 'large' ) );
    var_dump $bg['url']

    But the problem is when I need 3 sizes of the same image - then I need to call rwmb_meta 3 times, or use this workaround.
    If the rwmb_meta returns sizes - why the size['file'] can't contain also directory? What is the intended way to use the size['file']?
    I'd like to recommend to add "url" for sizes.

    #17877
    Anh TranAnh Tran
    Keymaster

    Hi,

    Thanks for your suggestion. I've added "url" to all sizes. It will available in the next version of Meta Box.

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