私はカスタムポストタイプであり、タイトル、コンテンツ、おすすめ画像を表示しようとしています。Get_postにデータが表示されない
これは私のコードです:
<?php
$args = array('posts_per_page' => -1, 'post_status' => 'publish', 'post_type' => 'testimonial');
$testimonialsposts = get_posts($args);
?>
<div class="row">
<?php
foreach ($testimonialsposts as $post)
{
setup_postdata($post);
?>
<div class="testimonial-box projectitem">
<img src="<?= get_post_meta($post->ID, '_wp_attached_file', true); ?>"/>
</div>
<div class="testimonial-contact">
<div class="testimonial-text"><?= get_post($post->ID, 'content', true); ?></div>
<div class="testimonial-name"><?= get_post($post->ID, 'post_title', true); ?></div>
<?php wp_reset_postdata();
} ?>
</div>
しかし、私は何を取得していないのです。 setup_postdataの後で詳細をエコーしてみましたが、それは "アレイ"をエコーしていました。
$ postをvar_dumpすると、すべてのデータも表示されます。
これは(> iはI var_dump
$post
オブジェクト(WP_Post)#614(24){[ "ID"] => INT(69)[ "post_author"] =得るもの 文字列であります(19)2017-08-22 02:26:43 ["post_date_gmt"] =>文字列(19) "2017-08-22 02:26:" 1 "[" post_date "] = Lorem Ipsumは、 の印刷物と植字業界のダミーテキストです。Lorem Ipsumは、 プリンタが入手した1500年代以来、業界標準のダミーテキストでした()。タイプのギャレーとそれをスクランブルしたoタイプ標本を作る 本。それは5世紀だけでなく、 への飛躍を生き延び、基本的に変わりはありません。 Lorem Ipsumパッセージを含むLetrasetシート のリリースで、さらに最近では、Lorem Ipsumのバージョンを含むAldus PageMakerのような公開ソフトウェア 公開ソフトウェアを使用して、1960年代に普及したのは でした。 "[" post_title "] => string(13)"["comment_status"] =>文字列(6) "閉じた" ["ping_status"] ["postimage"]"testimonial" ["to_ping"] =>文字列(0) "" ["post_password"] =>文字列(0) "" ["post_name"] =>文字列(6) "" post_modified_gmt "] => string(19)" ["pinged"] =>文字列(0) "" ["post_modified"] =>文字列(19) "2017-08-22 02:27:07" " "2017-08-22 02:27:07" ["post_cont ["guid"] =>文字列(63) "http://192.168.0.202/clinic202/?post_type=testimonial&p=69" ["menu_order"] => int(0) ["post_type"] => string(11) "testimonial" ["post_mime_type"] =>文字列(0) "" ["comment_count"] =>文字列(1) "0" ["filter"] => string(3) "raw"}
私は間違っていますか?
'echo()'の代わりに 'print_r()'を使って、配列の内容を表示することができます。それでも問題が解決しない場合は、あなたの投稿を更新して、配列が空であるかどうかを伝えてください。 – FluffyKitten
@FluffyKitten私はqnを更新しました – Jackson
全体を投稿する必要はありませんでした。 - )OKですので、あなたのクエリは機能していますが、ループはすべて間違っています - 単に 'get_the_title'や' get_the_content'を使うのではなく、何らかの理由で 'get_post'を使用していて、' testimonial-contact' div正しい場所に保管してください。 – FluffyKitten