0
我正在使用重力形式插件,並試圖在我已創建的窗體中顯示類別作爲下拉列表。從數據庫中提取數據並以重力形式顯示
如果需要的話,請在這裏對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;
}
嗨庫馬爾,謝謝你的幫助,對不起,這個回覆遲到了,我做了一個緊急的行程,讓項目暫停。我按照你發送的鏈接上的步驟進行了操作,但它沒有給我列出我的類別,也許我沒有把它做對。我已經添加了我在這篇文章中使用的php代碼,以防萬一你想看看它。再次感謝 –