post thumb nail

I retrieve information from database postmeta table.
I have 2 custom post type ‘book’ and ‘author’ I using metabox to connect them together. when user go to book custom post and adding new book. he must use check box metabox to determined which author write this book.

I have another page in my website which show author profile. in this page user can see books of author, my codes can save author for each book in database and read them perfectly and also can retrieve books of any author.

here is my problem I want to find each book feature image but when I use get_the_post_thumbnail it doesn’t give me anything.

how can I fix this

I use var_dump to see each book information
here is the picture of it.
enter image description here

and here is my codes

<?php $args = array( 'post_type' => 'author'); 
    $loop = new WP_Query( $args );
     while ( have_posts() ) : the_post(); ?>

    <div class="title-pack col-md-12 col-sm-12 col-xs-12">
        <span class="line visible-sm-block"></span>
        <span class="visible-sm-block tittle-style"><?php the_title(); ?></span>
    </div>
    <div class="row writer-crit">
        <div class="writer-crit-box col-md-9 col-sm-8 col-xs-12">
            <div class="col-md-11 col-sm-11 col-xs-12 pull-right">
                <div class="writer-bio pull-right col-md-12 col-sm-12 col-xs-12">
                    <?php the_post_thumbnail('post-thumbnail',array('class' => 'pull-right')); ?>
                    <div class="writer-content-bio col-md-8 col-sm-8 col-xs-12 pull-right">
                        <h3><?php the_title(); ?></h3>
                        <?php the_content(); ?>
                    </div>
                    <div class="col-md-12 col-sm-12 col-xs-12 pull-right">
                            <h3>کتابشناسی </h3>
                            <?php $ars = array( 'post_type' => 'book'); 
                            $loop = new WP_Query( $ars );

// for reading author which choose from cheak box in each book pages.
                            $post_id = get_the_ID();

                            $key = 'save-author-to-book';
                            $key2='save-trans-to-book';
                            // $vals=get_post_meta($post_id, $key2, true);
                            // $values = get_post_meta( $post_id, $key, true );
                            $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
                            global $wpdb;
                            $x=(string) $post_id;
                            $sql="SELECT post_id FROM wp_postmeta WHERE meta_key = "save-author-to-book" AND meta_value LIKE "%".$x.'%"';
                            $results = $wpdb->get_results( $sql, OBJECT );
                            foreach ($results as $result ) {
                                $array[]=$result->post_id;

                            }
                            foreach ($array as $arr) { ?>
                                <?php $autr_book=get_post($arr);

                                //var_dump($autr_book);?>
                                <li class="">
                                    <a href="https://wordpress.stackexchange.com/questions/237820/<?php echo $autr_book->guid;?>">
                                    <div><?php get_the_post_thumbnail( $autr_book->ID ); ?></div>
                                <p><?php echo $autr_book->post_title; ?></p>
                                </a>
                                </li>
                            <?php } ?>

                    </div>
                </div>
            </div>
        </div>


<?php endwhile; // End of the loop. ?>
<!-- ====================================

2 Answers
2

You use the function get_the_post_thumbnail() which returns a string. So you need to print that string with echo or use the_post_thumbnail() which echos itself.

Leave a Comment