2015-03-02 43 views
0

試圖在標題中儘可能具體。基本上我有一個房地產網站,我正在工作,有屬性列表。屬性列表是一個自定義的帖子類型,並且有幾個其他的自定義帖子類型(每個都有自己的自定義字段)附加到它。使用自定義帖子類型的自定義字段動態預填充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」重力表單字段。如果有人知道我能夠將此字段(或代理自定義帖子中的任何字段)遺漏到此表單中,我們將非常感謝。

謝謝。

回答

0

我工作的這一個,現在 - 我能夠從一個頁面值傳遞給另一個信息附加到URL的末尾 -

前。 http://www.your-website.com/[email protected]

爲此,您必須在編輯有問題的字段時勾選'允許此字段有條件填充'。

對我來說這不是一切皆有可能(我希望在頁面加載時生成此信息,而不是將其附加到按鈕上,但這是一個開始,當我擁有過濾解決。

亞當

+0

欣賞亞當,我碰到這種方法就很好,但遺憾的是它不適合我的需要,我也需要它在頁面加載填充。如果你想要別的東西,期待聽到回來。 – tystra 2015-03-08 04:09:50

0

這裏是我的填充方式使用,我發現約書亞大衛納爾遜創造了一些代碼,我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')。

如果您對上述代碼有任何疑問,請告訴我。

亞當

相關問題