使用自定义帖子类型的自定义字段动态预填充Gravity Forms字段
试图在标题中尽可能具体。基本上我有一个房地产网站,我正在工作,有属性列表。属性列表是一个自定义的帖子类型,并且有几个其他的自定义帖子类型(每个都有自己的自定义字段)附加到它。使用自定义帖子类型的自定义字段动态预填充Gravity Forms字段
每个属性都具有的试剂(自定义后型)连接到它与自定义字段,如电子邮件,脸谱,电话号码等
我需要动态预先填充与所述重力形式的隐藏字段代理电子邮件(与作者电子邮件不同),以便我可以发送电子邮件到该地址。
我已经尝试了以下,没有运气,因为我确定缺少一些代理自定义帖子类型中的自定义字段,但我不知道如何。这就是我与迄今为止的工作:
add_filter('gform_field_value_agentemail', 'populate_post_agent_email');
function populate_post_agent_email($value){
global $post;
$agents_email = get_post_meta($post->ID, 'agent_email', true);
return $agents_email;
}
我已经加入参数名“agentemail”重力表单字段。如果有人知道我能够将此字段(或代理自定义帖子中的任何字段)遗漏到此表单中,我们将非常感谢。
谢谢。
我工作的这一个,现在 - 我能够从一个页面值传递给另一个信息附加到URL的末尾 -
前。 http://www.your-website.com/[email protected]
为此,您必须在编辑有问题的字段时勾选'允许此字段有条件填充'。
对我来说这不是一切皆有可能(我希望在页面加载时生成此信息,而不是将其附加到按钮上,但这是一个开始,当我拥有过滤解决。
亚当
这里是我的填充方式使用,我发现约书亚大卫纳尔逊创造了一些代码,我GravityForms下拉,[email protected]
有一些小的修改,我能以获得适当的输出到下拉框(寻找用户电子邮件地址,而不是用户nicenames,但你可以修改这个脚本为o本安输出任何你想用一些小的改动,以查询参数)
// Gravity Forms User Populate, update the '1' to the ID of your form
add_filter('gform_pre_render_1', 'populate_user_email_list');
function populate_user_email_list($form){
// Add filter to fields, populate the list
foreach($form['fields'] as &$field) {
// If the field is not a dropdown and not the specific class, move onto the next one
// This acts as a quick means to filter arguments until we find the one we want
if($field['type'] !== 'select' || strpos($field['cssClass'], 'your-field-class') === false)
continue;
// The first, "select" option
$choices = array(array('text' => 'Just Send it to the Default Email', 'value' => '[email protected]'));
// Collect user information
// prepare arguments
$args = array(
// order results by user_nicename
'orderby' => 'user_email',
// Return the fields we desire
'fields' => array('id', 'display_name', 'user_email'),
);
// Create the WP_User_Query object
$wp_user_query = new WP_User_Query($args);
// Get the results
$users = $wp_user_query->get_results();
//print_r($users);
// Check for results
if (!empty($users)) {
foreach ($users as $user){
// Make sure the user has an email address, safeguard against users can be imported without email addresses
// Also, make sure the user is at least able to edit posts (i.e., not a subscriber). Look at: http://codex.wordpress.org/Roles_and_Capabilities for more ideas
if(!empty($user->user_email) && user_can($user->id, 'edit_posts')) {
// add users to select options
$choices[] = array(
'text' => $user->user_email,
'value' => $user->id,
);
}
}
}
$field['choices'] = $choices;
}
return $form;
}
/* end of populate advisors for dropdown field */
为了得到这个工作,你应该需要做的就是上面的代码添加到您的functions.php文件,添加“ID”(进入add_filter引用)GravityForm,你正在寻找改变并添加你的下拉字段的'Class'(其中是'your-field-class')。
如果您对上述代码有任何疑问,请告诉我。
亚当
欣赏亚当,我碰到这种方法就很好,但遗憾的是它不适合我的需要,我也需要它在页面加载填充。如果你想要别的东西,期待听到回来。 – tystra 2015-03-08 04:09:50