2017/10/19
カスタムフィールド
備忘録です。
ループ外でカスタムフィールドの値を取得する方法です。
参考サイト
[WordPress]ループ外でカスタムフィールドの値を取得する記述。
表示したいテンプレートに記述
<?php
global $wp_query;
$postID = $wp_query->post->ID;
$customfield = get_post_meta($postID, 'フィールド名', true);
echo $customfield;
?>
条件指定(入力の有無)を入れる場合
<?php
global $wp_query;
$postID = $wp_query->post->ID;
$customfield = get_post_meta($postID, 'フィールド名', true);
?>
<?php if(empty($customfield)):?>
空欄だった場合に表示されます。
<?php else:?>
記述が有る場合に表示されます。
<?php echo post_custom('フィールド名');?>
<?php endif;?>
2026/11/07
神社
2026/11/06
AI
2026/11/05
Wordpress
ホームページ制作
2026/11/04
Mac
2026/11/03
AI