无法将类stdClass的对象转换为中的字符串

时间:2019-08-13 作者:ncti

我遇到了一个问题,我遇到了这个错误,stdClass类的对象无法转换为字符串

global $wpdb;

$poster_id = $wpdb ->get_results("SELECT ID from wp_posts WHERE post_status=\'publish\' AND post_type=\'post\' AND post_content LIKE \'%[gallery%\' ORDER BY ID DESC");

$link_sluger = $wpdb ->get_results("SELECT guid FROM wp_posts WHERE post_name LIKE \'albums%\' ORDER BY guid DESC");

   foreach ( array_combine($poster_id, $link_sluger) as $posters_id => $linker_slugerr){
        global $post;
        $post = get_post($posters_id->ID);
        $linker_sluger = $linker_slugerr->guid;

            if(has_shortcode( $post->post_content, \'gallery\' ) ){

                echo\'<div class="single-album home-last-gallery col-md-4 col-sm-12"> <a href="\'.$linker_sluger.\'">\';
                echo na_get_gallery_image_urls($posters_id->ID, $linker_sluger); 
                echo \'</a></div>\';

             }

    }

1 个回复
SO网友:ncti

我解决了它。只需更改:

foreach( $poster_id as $index => $posterss_id ) {
    global $post;
    $post = get_post( $posterss_id->ID );
    $linker_sluger = $link_sluger[$index]->guid; 
    /* ... */
}
完整解决方案:

global $wpdb;

$poster_id      = $wpdb ->get_results( "SELECT ID from wp_posts WHERE post_status=\'publish\' AND post_type=\'post\' AND post_content LIKE \'%[gallery%\' ORDER BY ID DESC" );
$link_sluger    = $wpdb ->get_results("SELECT guid FROM wp_posts WHERE post_name LIKE \'albums%\' ORDER BY guid DESC");

foreach( $poster_id as $index => $posterss_id ) {

    global $post;
    $post = get_post($posterss_id->ID);
    $linker_sluger= $link_sluger[$index]->guid;

    if( has_shortcode( $post->post_content, \'gallery\' ) ){

        echo\'<div class="single-album home-last-gallery col-md-4 col-sm-12"> <a href="\'.$linker_sluger.\'">\';
        echo na_get_gallery_image_urls($posterss_id->ID, $linker_sluger); 
        echo \'</a></div>\';

    }

}

相关推荐

为什么dbDelta()不能捕获MysqlErrors?

据我所见,dbDelta() 用于抑制在其操作过程中发生的数据库错误。一般来说,情况似乎是这样,但New Relic仍在报告函数中的MysqlErrors。准确的错误消息格式如下:MysqlError: Table \'xxx.wp_yyy_posts\' doesn\'t exist 发件人dbDelta() 在里面/wp-admin/includes/upgrade.php, 我们有:// Fetch the table column structure from the database&