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代码,以防万一你想看看它。再次感谢 –