我已经成功地在重力表单下拉列表中填充了来自网络主站点的贴片。请参见下面的代码。
为了列出子网站的帖子标题,我需要添加什么代码?
任何见解都将不胜感激。
add_filter( \'gform_pre_render_20\', \'select_questionnaire\' );
add_filter( \'gform_pre_validation_20\', \'select_questionnaire\' );
add_filter( \'gform_pre_submission_filter_20\', \'select_questionnaire\' );
add_filter( \'gform_admin_pre_render_20\', \'select_questionnaire\' );
function select_questionnaire( $form ) {
foreach ( $form[\'fields\'] as &$field ) {
if ( $field->type != \'select\' || $field->id . \'1\' === false ) {
continue;
}
$posts = get_posts( \'numberposts=-1&post_status=publish&post_type=questionnaire\' );
$choices = array();
$choices[] = array("text" => "Select Questionnaire", "value" => "");
foreach ( $posts as $post ) {
$choices[] = array( \'text\' => $post->post_title, \'value\' => $post->post_title );
}
// update \'Select a Post\' to whatever you\'d like the instructive option to be
$field->choices = $choices;
}
return $form;
}