Invalid argument supplied...

Support General Invalid argument supplied...

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #9276
    lhkeeperlhkeeper
    Participant

    Dear Support,

    I created the WordPress theme where I used custom fields based on meta box plugins. I also included all required plugins (e.g. meta box, meta box groups etc) in my theme. Everything is working fine on my testing site but if only I wanted to install this theme on the new site I am getting warnings and cannot do anything. Please have a look:

    Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\wordpress\wp-content\plugins\meta-box\inc\meta-box.php on line 105

    Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\wordpress\wp-content\plugins\meta-box\inc\meta-box.php on line 77

    Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\wordpress\wp-content\plugins\meta-box\inc\meta-box.php on line 369

    Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\wordpress\wp-content\plugins\meta-box\inc\meta-box.php on line 105

    Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\wordpress\wp-content\plugins\meta-box\inc\meta-box.php on line 77

    The custom meta boxes I created are in a sub folder in my theme as a part of it. Should I add them as a separate plugin though?

    Please help me as I do not know what to do now.
    Kasia

    #9277
    lhkeeperlhkeeper
    Participant

    ah also those two lines in the end I have:

    Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\wordpress\wp-content\plugins\meta-box\inc\meta-box.php:369) in C:\xampp\htdocs\wordpress\wp-content\plugins\unyson\framework\includes\hooks.php on line 256
    Warning: array_unique() expects parameter 1 to be array, null given in C:\xampp\htdocs\wordpress\wp-includes\post-template.php on line 772

    Warning: join(): Invalid arguments passed in C:\xampp\htdocs\wordpress\wp-includes\post-template.php on line 557
    class="">

    #9278
    Anh TranAnh Tran
    Keymaster

    Hello,

    Can you share the code to register meta boxes? I guess there're some things missed there.

    #9279
    lhkeeperlhkeeper
    Participant

    Hi Anh 🙂

    There you go:

    /**
     * Displaying all custom metaboxes
     */
    
    add_filter( 'rwmb_meta_boxes', 'lhk_register_home_meta_boxes' );
    
    function lhk_register_home_meta_boxes( $meta_boxes ) {
    
    $files_contact          =  glob( get_template_directory() .'/inc/contact-mod/<em>.php' );
    $files_csi              =  glob( get_template_directory() .'/inc/csi-mod/</em>.php' );
    $files_general          =  glob( get_template_directory() .'/inc/general-mod/<em>.php' );
    $files_home             =  glob( get_template_directory() .'/inc/home-mod/</em>.php' );
    $files_how              =  glob( get_template_directory() .'/inc/how-mod/<em>.php' );
    $files_prod             =  glob( get_template_directory() .'/inc/product-mod/</em>.php' );
    $files_post             =  glob( get_template_directory() .'/inc/post-mod/<em>.php' );
    $files_testimonials     =  glob( get_template_directory() .'/inc/testimonials-mod/</em>.php' );
    
    $all_files = [ $files_contact, $files_csi, $files_general , $files_home, $files_how , $files_prod , $files_post, $files_testimonials  ];
    
    foreach ( $all_files as $key => $files ) {
        foreach( $files as $file ){
    
        $meta_boxes[] = include $file;
    
        }
    }
    
    return $meta_boxes;
    }

    Thank you 🙂

    #9280
    lhkeeperlhkeeper
    Participant

    By the way I am using TGM Activation Class to include your plugins, if it can help anyhow...

    #9282
    lhkeeperlhkeeper
    Participant

    Ahn, I am just wondering... If I registered some fields e.g. email filed this way:

    [
    'id' => 'contact_email',
    'type' => 'email',
    'name' => esc_html__( 'Email:', 'lhk' ),
    'desc' => esc_html__( 'Please insert your email here.', 'lhk' ),
    'size' => 50,
    ],

    where 'type' is 'email' instead of e.g. 'text' could it caused the problem?
    I have a few fields registered as 'type' => 'url' .... when I checked the documentation there are no these types of fields...

    #9285
    lhkeeperlhkeeper
    Participant

    As an example I am giving you the code for a one meta box I created. If you wish to see all files please let me know.

    All the meta boxes are created in this way:

    https://pastebin.com/3VPA1skm

    #9293
    Anh TranAnh Tran
    Keymaster

    Hi,

    I've just checked your code and couldn't see the error. Here is my test:

    https://i.imgur.com/GBe6C7B.gif

    Probably it's somewhere else. Can you check if there's any meta box that doesn't have any field?

    I see you use glob to include all PHP files in a folder. Maybe there's a PHP file that doesn't contain meta box code?

    #9318
    lhkeeperlhkeeper
    Participant

    Hi Anh,

    I hope you had a good weekend. Thank you for all your help and concern. I checked everything once again and.... instead of returning each meta box (code) in each file I assigned it to meta boxes array..so in the end, I was trying to nest a meta boxes array in meta boxes array 🙂 I am not sure if I explain it clearly enough 🙂 Long story short, my each file started like this:

    $meta_boxes[] = [
    'title' => esc_html__( 'Service Testimonials', 'lhk' ),
    'post_types' => [
    'page',
    ],.....
    etc......

    and should like this:

    return[
    'title' => esc_html__( 'Service Testimonials', 'lhk' ),
    'post_types' => [
    'page',
    ],......
    etc.......
    It caused all these errors.

    Thank you again Anh
    Best,
    Kasia

    #9320
    Anh TranAnh Tran
    Keymaster

    Hey Kasia, no problem at all. I'm glad you figured it out!

    If you need any help, please let me know.

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Invalid argument supplied...’ is closed to new replies.