
>
Wordpress > wordpress contact-form-7にカスタムフィールドの値を渡す
wordpress contact-form-7にカスタムフィールドの値を渡す 2015年5月27日
Tag:
カスタムフィールドの値をコンタクトフォームに表示させる方法です。
例:カスタムフィールドの値
title
moon
1.functions.phpに下記を追加
// contact form7 値渡し
function my_form_tag_filter($tag){
if ( ! is_array( $tag ) )
return $tag;
if(isset($_GET['title'])){
$name = $tag['name'];
if($name == 'title')
$tag['values'] = (array) $_GET['title'];
}
if(isset($_GET['moon'])){
$name = $tag['name'];
if($name == 'moon')
$tag['values'] = (array) $_GET['moon'];
}
return $tag;
}
add_filter('wpcf7_form_tag', 'my_form_tag_filter', 11);
2.コンタクトフォームへの記入
3.singleページなどにコンタクトフォームへのリンクボタンを設置
<a href="<?php echo home_url(); ?>/application/?title=<?php echo urlencode(get_the_title());?>&moon=<?php echo get_post_meta($post->ID,"moon",true); ?>"><input type="button" value="申し込む" /></a>