您可以尝试在联系人表单的链接中向url添加get参数。
如果是灯箱样式,还可以定义一个隐藏字段,并在wpcf7加载时使用global$post填充它。
将此代码用于url参数解决方案,并将id\\u post替换为lightbow解决方案的global$post->id:
//Add the post id
function add_post_id_origin ( $tag, $unused ) {
//First we test if it\'s our hidden field
if ( $tag[\'name\'] != \'myhiddentag\' )
return $tag;
//This is for the url param version
if(isset($_GET[\'id_post\']) && is_numeric($_GET[\'id_post\']))
{
$post = get_post($_GET[\'id_post\']);
$tag[\'values\'] = array($post->ID);
$tag[\'options\'] = array(\'readonly\');
}
//this way for a regulare global $post usage
global $post;
$tag[\'values\'] = array($post->ID);
$tag[\'options\'] = array(\'readonly\');
return $tag;
}
//Don\'t forget to hook the function
add_filter( \'wpcf7_form_tag\', \'add_post_id_origin\', 10, 2);