Warning: Undefined array key "postid_history" in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/functions.php on line 811
フィールド値の出力 | DUB DESiGN
Warning: Undefined array key 3 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 18

Warning: Undefined array key 4 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 21

Warning: Undefined array key 3 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 30

Warning: Undefined array key 4 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 33

WordPress
関数リファレンス

お気に入り登録

フィールド値の出力

Warning: Undefined variable $checked_items in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/rss/favorite_button.php on line 21

お気に入り登録をすると、お気に入り記事一覧に登録することができます。

フィールド値の出力

フィールドの出力


Warning: Undefined array key 3 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 18

Warning: Undefined array key 4 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 21

Warning: Undefined array key 3 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 30

Warning: Undefined array key 4 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 33

functions.php にコードを記述して作ったカスタムフィールドの値を取得して出力します。

カスタムフィールドを使う時、使用頻度が多いコードなので覚えておくと便利です。

フィールド値の出力

フィールド値の出力は、get_post_meta() の関数を使います。

PHP

<?php echo get_post_meta($post->ID , 'youtube' ,true); ?>

表示するフィールド名を変更する場合、 get_post_meta($post->ID , 'youtube' ,true) 内のフィールド名 youtube 部分を変更すればOKです。

フィールドの値がない場合出力を除外

入力されているカスタムフィールド値を get_post_meta() で取得して、値がない場合 if で出力を除外します。

PHP

<?php if(get_post_meta($post->ID, 'youtube',true)): ?><?php echo get_post_meta($post->ID , 'youtube' ,true); ?><?php endif; ?>

フィールドに何も入力されてない場合何も出力しないので、この設置方法が実用的です。

カスタムフィールドの入力有無で条件分岐

get_post_meta() の関数を使い、カスタムフィールドの入力の有無を判定して、出力する内容を分岐させます。

PHP

<?php if(get_post_meta($post->ID, 'youtube',true)): //入力がある場合 ?>

<?php echo get_post_meta($post->ID , 'youtube' ,true); ?>
   
<?php else: // 入力がない場合 ?>

<!-- 入力がない場合の出力 -->
   
<?php endif; ?>


Warning: Undefined array key 3 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 18

Warning: Undefined array key 4 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 21

Warning: Undefined array key 3 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 30

Warning: Undefined array key 4 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 33