カスタムフィールドで登録したデータを表示

前回の記事で作成したカスタムフィールドをWEB上に表示する方法を紹介します。

表示したい場所に下記のコードを埋め込む

<?php $myQuery = new WP_Query(); // WP_Queryオブジェクト生成 $param = array( //パラメータ。 'posts_per_page' => '9', //(整数)- 1ページに表示する記事数。-1 ならすべての投稿を取得。 'post_type' => 'seminar', //カスタム投稿タイプのみを指定。 'post_status' => 'publish', //取得するステータスを指定:publish(公開済み) 'orderby' => 'day', 'order' => 'ASC' //昇順。小さい値から小大さい値の順。 ); $myQuery->query($param); // クエリにパラメータを渡す?>

詳しい説明は横の注釈を呼んで設定して下さい。
以下のコードが実行部分

<?php if($myQuery->have_posts()): while($myQuery->have_posts()) : $myQuery->the_post(); ?><?php the_field('タイトル'); ?>
<?php the_field('画像'); ?>
<?php the_field('リンク先'); ?><?php endwhile; endif; ?><?php wp_reset_postdata(); ?>

if から END while迄が実行部分で<?php the_field(‘画像’); ?>部分がカスタムフィールドで設定した項目の出力タグ

あとは、HTMLとCSSを駆使して形を整えてこのタグを挿入すれば完成です。