配列に含まれる各投稿のサムネイルを取得できません。
カスタム投稿タイプのすべての投稿を含むこの配列があります。
<?php
$clients_array = array(
'post_type' => 'clients',
'sort_order' => 'ASC',
'sort_column' => 'post_title',
'post_status' => 'publish'
);
?>
次のように、標準のワードプレスループを使用してサムネイルを取得するのに問題はありませんが:
<?php
$query = new WP_Query( $clients_array );
while ( $query->have_posts() ) : $query->the_post();
?>
<?php if ( has_post_thumbnail()) : ?>
<?php the_post_thumbnail() ?>
<?php
endif;
endwhile;
?>
次のような foreach ルックで投稿をロードしたいと思います。
<?php
$clients = get_pages($clients_array);
foreach ($clients as $page_data) {
$client_id = $page_data->ID;
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($client_id), 'thumbnail' );
echo $thumb;
}
?>
残念ながら、私が試した方法ではうまくいきません。
私は何を間違っていますか?