admin管理员组

文章数量:1289834

I am having a problem , I am getting this error, Object of class stdClass could not be converted to string

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>';

             }

    }

I am having a problem , I am getting this error, Object of class stdClass could not be converted to string

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>';

             }

    }
Share Improve this question edited Aug 13, 2019 at 12:21 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Aug 13, 2019 at 12:17 nctincti 135 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 1

I solved it. Just change:

foreach( $poster_id as $index => $posterss_id ) {
    global $post;
    $post = get_post( $posterss_id->ID );
    $linker_sluger = $link_sluger[$index]->guid; 
    /* ... */
}

Full Solution:

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>';

    }

}

本文标签: errorsObject of class stdClass could not be converted to string in