Image Advanced Warning

Support General Image Advanced Warning

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #10977
    tsqueztsquez
    Participant

    Hi there,

    First, I do have WP_DEBUG set to true on my development site, which I think anyone who is developing themes or plugins should have.

    Secondly, I have created a custom post type. It is all set up and working beautifully thanks to your Custom Post Type plugin.

    OK, so I wanted to try and use the Image Advanced field for a certain part of the custom post type and I added the following:

    $images = rwmb_meta( 'info', array( 'limit' => 1 ) );
    $image = reset( $images );

    This of course comes from the docs: https://docs.metabox.io/fields/image-advanced/#template-usage.

    I changed it to this:

    $images = rwmb_meta( 'tp_primo_header_background',array( 'size' => 'full' ) );
    $image = reset( $images );

    which is supposed to return the full size image. The image displays properly the way it's supposed to in the custom post type...awesome.

    However, when you I view a regular post or page, which of course is not the custom post type, I get the following warning:

    Warning: reset() expects parameter 1 to be array, string given in /the file where the code is added on line 8

    I know if I turn off WP_DEBUG the warning message will go away but I am curious as to how can I get rid of that warning altogether?

    Thanks in advance for any help.

    #10980
    Anh TranAnh Tran
    Keymaster

    Hi Thomas,

    I think the problem is where you put the code that gets the image. For the template that doesn't have header background, you should perform a simple check like this:

    $images = rwmb_meta(...);
    if ( $images ) {
        $image = reset( $images );
        echo $image;
    }
    #10985
    tsqueztsquez
    Participant

    Awesome Anh, that worked perfectly and the warning went away.

    As always, thank you very much.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Image Advanced Warning’ is closed to new replies.