2016-08-21 127 views
0

我正在使用重力形式插件,並試圖在我已創建的窗體中顯示類別作爲下拉列表。從數據庫中提取數據並以重力形式顯示

enter image description here

如果需要的話,請在這裏對my website

我已經在這個時間過長的鏈接,並沒有出路。請幫助我。

add_filter('gform_pre_render_1', 'populate_categories'); 
 
add_filter('gform_pre_validation_1', 'populate_categories'); 
 
add_filter('gform_pre_submission_filter_1', 'populate_categories'); 
 
add_filter('gform_admin_pre_render_1', 'populate_categories'); 
 
function populate_categories($form) { 
 

 
    foreach ($form['fields'] as &$field) { 
 

 
     if ($field->id != 1) { 
 
      continue; 
 
     } 
 

 
     // you can add additional parameters here to alter the posts that are retrieved 
 
     // more info: [http://codex.wordpress.org/Template_Tags/get_posts](http://codex.wordpress.org/Template_Tags/get_posts) 
 
     $categories = get_categories ; 
 

 
     $choices = array(); 
 

 
     foreach ($categories as $categories) { 
 
      $choices[] = array('text' => $categories->name, 'value' => $categories->name); 
 
     } 
 

 
     // update 'Select a Post' to whatever you'd like the instructive option to be 
 
     $field->placeholder = 'Category'; 
 
     $field->choices = $choices; 
 

 
    } 
 

 
    return $form; 
 
}

回答

0

可以動態生成使用這個鏈接下面提供的語法形式重心的下拉菜單。您必須控制主題的functions.php文件以按照您的要求檢索您的輸出。

以下是提供的清晰文檔,您可以使用此方法以簡單方式創建。有兩種方法可以參考它。

https://www.gravityhelp.com/documentation/article/dynamically-populating-drop-down-fields/

如果你面對任何創作問題讓我知道,我們將解決這個問題。

+0

嗨庫馬爾,謝謝你的幫助,對不起,這個回覆遲到了,我做了一個緊急的行程,讓項目暫停。我按照你發送的鏈接上的步驟進行了操作,但它沒有給我列出我的類別,也許我沒有把它做對。我已經添加了我在這篇文章中使用的php代碼,以防萬一你想看看它。再次感謝 –

相關問題