$post_id;//投稿のID
$key = 'size';//カスタムフィールドのキー
$single = true;//文字列を取得する
$thumb_size = get_post_meta($post_id, $key, $single);
the_post_thumbnail($thumb_size);
こんな感じでどうでしょうか?
post_idを取得して頂く必要はありますが・・・
<?php
$post_id;
$key = 'size';
$single = true;
$thumb_size = get_post_meta($post_id, $key, $single);
the_post_thumbnail($thumb_size);
?>
と書いてみたのですが、
どうも値が取得できていないみたいです。
全体的には、
「メニュー」というカスタムポストタイプの投稿で、
カスタムタクソノミー「メニューカテゴリー」の中の
「食べ物」のサムネイルを表示するという前提で、
カスタムフィールドにてboxサイズを指定し、
そのboxサイズに応じたサムネイルを表示したい
という感じです。
<div class="collect cf">
<?php
$args = array(
'posts_per_page' => -1,
'post_type' => 'menu',
'tax_query' => array( /* カスタム分類 */
array(
'taxonomy' => 'メニューカテゴリー',
'field' => 'slug',
'terms' => '食べ物',
)
)
);
?>
<?php $the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="box <?php echo (post_custom('size')); ?>">
<div class="left">
<a href="<?php the_permalink(); ?>"><div class="thum">
<?php
$post_id;
$key = 'size';
$single = true;
$thumb_size = get_post_meta($post_id, $key, $single);
the_post_thumbnail($thumb_size);
?>
</div></a>
</div>
<div class="right">
<h4 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<?php if(post_custom('price')): ?><div class="price"><?php echo nl2br(post_custom('price')); ?></div><?php endif; ?>
<?php if(post_custom('cap')): ?><div class="cap"><?php echo nl2br(post_custom('cap')); ?></div><?php endif; ?>
</div>
</div>
<?php endwhile; endif; ?><?php wp_reset_postdata(); ?>
</div>
$post_idは投稿のIDを入れる必要があります。
ループ内なら$post->IDで取得できますので
$post_id = $post->IDに変更してください。
ありがとうございます!
<?php
$post_id = $post->ID;
$key = 'size';
$single = true;
$thumb_size = get_post_meta($post_id, $key, $single);
the_post_thumbnail($thumb_size);
?>
このようにしたら部解決しました!
ありがとうございます!