可捕获的致命错误:类WP_Post的对象无法转换为字符串

maybe I've been at this for too long but I can't figure out why my function is giving me the above error.

What I'm trying to do is let wordpress display it's child pages.

function childpages_func( $childpages = '' ){
  $childpages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc&parent='.$post->ID);
    foreach($childpages as $child){
        "<div>
            <a href='.get_page_link($child->ID).' title='.$child->post_title.'>
                <img src='.wp_get_attachment_url(get_post_thumbnail_id($child->ID)).' title='.$child->post_title.'>
            </a>
        </div>";
    }
    return $childpages;
}

And the output function:

function vc_doo_clip_child_pages_func( $atts ) {
 extract( shortcode_atts( array(
        'cp_header' => 'cp_header'
    ), $atts ) );
     $end_content = '<h2>'.$cp_header.'</h2>'.childpages_func().'';

        return $end_content;
}

Any help will be greatly appreciated.

Thanks.

Your function is wrong formated. return must be outer than foreach block. you didn't show any text. You must write an echo before your text block or set any variable.

You can not return $child variable!