Custom Fields
Re-Envisioned
Support MB REST API How to show image url with folder in all sizes from Rest API

  • Creator
    Topic
  • #16391
    Resolved PTiCA
    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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #16412
    Anh 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
    PTiCA
    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
    Caballero
    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 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 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Newsletter

Subscribe to our newsletter to receive news and tutorials for Meta Box and WordPress.


grid gear info copy caret-up caret-down trash