カスタムフィールドの値を取得

  • [sc_post_custom key=” “]
  • key=フィールドキー
  • フィールド値を表示
    • 値が複数のとき
    • separator=区切り


custom-field


custom-field


WordPress の便利な機能「カスタムフィールド」と連携。(最近 Movable Type にも実装されたらしい)

function sc_post_custom_func( $atts, $content = null ) {
	extract( shortcode_atts( array(
					'key' => '',
					'separator' => ', ',
					), $atts ));
	if ( is_array(post_custom($key)) ) {
		return implode($separator,post_custom($key));
	} else {
		return post_custom($key);
	}
}
add_shortcode( 'sc_post_custom', 'sc_post_custom_func' );

詳細はカスタムフィールドのデータ表示を参照。

コメントは受け付けていません。