Advanced custom field のコード記載例

Advanced custom field

シンプルにカスタムフィールドを表示する

 

フィールドタイプ/画像

返り値の選択肢(画像オブジェクト・画像URL・画像 ID) で「画像URL」を選択した場合

 

条件つき(もし値が入力されていたら)

グーグルマップで地図を表示するのに一番簡単だった方法

デフォルトのカスタムフィールドに住所を入力する方法

wordpressにデフォルトでついているカスタムフィールドに住所を入力する方法 → カスタムフィールドに住所を入力 → グーグルマップで地図表示

これが一番簡単でした。下記のコードを表示したい場所に記入するだけ

<?php if ( post_custom(‘event_address’) ) : ?>

<?php

$addressformap = post_custom(‘event_address’);

$addressformapencode = urlencode(mb_convert_encoding($addressformap, “UTF-8″,”auto”));

?>

<iframe width=”90%” height=”350″ frameborder=”5″ scrolling=”no” marginheight=”0″ marginwidth=”0″ src=”http://maps.google.co.jp/maps?q=<?php echo $addressformapencode; ?>&z=18&output=embed”></iframe>

<?php else : ?>

<p>Sorry, No map.</p>

<?php endif; ?>

Advanced custom field のフィールドタイプ「Google map」を使う方法

公式のページ Creating a Google Map field に書いてあった下記のコード1と2を「single-ポストタイプ.php」にコピペ。3のCSSは「style.css」にコピペしたらやっと表示されたけど住所を入力しても反映されない。マーカーを自分で動かさなきゃいけなくて使えなかった

1 Render a single maker onto a map

3 CSS