I'm new to WordPress, and I'm having an issue with "The Loop." I have 2 custom post type named 'book' and 'author' .in author post type I have custom filed checkbox which can choose between author and translator. also in book post type I have 2 metaboxs which user must choose the name of author and translator from those. all metabox and custom post type work well but when I want to call them and use the values of each meta-box I have problem. my code can read author values well, but translator values just show the last value of author and I cant' figure out why this happen ? I think foreach is the problem. but I don't know how can I solve it. here is my code for single-book.php
<?php $args = array( 'post_type' => 'book');
$loop = new WP_Query( $args );
while ( have_posts() ) : the_post();
// 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) );
?>
echo '<h4 class="text-right color-style"> نویسنده : ';
foreach($values as $value){
$author=get_post($value);
echo '<a href="'.
get_post_permalink($value).'" target="_blank">'.
$author->post_title .'</a> ، ' ;}
echo '</h4>';
echo '<h4 class="text-right color-style"> مترجم : ';
foreach($vals as $val){
$trans=get_post($val);
echo '<a href="'.
get_post_permalink($val).'" target="_blank">'.
$author->post_title.'</a>، ';}
echo '</h4>';
any idea would be appreciated.
$trans->post_title.'</a>، ';}...