希望有人能帮助新手,因为我不知道该怎么做。
我的functions.php中有下面的代码,它填充了产品的GravityForms表单“复选框列表”。用户使用复选框在网站上选择GF表单中的产品。每个被拖到复选框列表中的产品都是一个单独的WordPress帖子。
我很难按字母顺序对复选框进行排序,这样用户就可以很容易地在100+不同的产品(帖子)中找到产品。
我找不到任何其他论坛的帖子看起来有点相似,这样我就可以自己想出如何分类了。
第一部分是按字母顺序排列复选框,
我需要的第二部分是排除两个贴上“系统”标签的员额,或者排除这两个员额,因为它们被归类为“系统”员额。
非常感谢,
安德烈
/**
* Add Gravity Forms function to dynamically populate customer
* letter checkboxes
* applicious
*/
//NOTE: update the '1' to the ID of your form
add_filter( 'gform_pre_render_1', 'populate_checkbox' );
add_filter( 'gform_pre_validation_1', 'populate_checkbox' );
add_filter( 'gform_pre_submission_filter_1', 'populate_checkbox' );
add_filter( 'gform_admin_pre_render_1', 'populate_checkbox' );
function populate_checkbox( $form ) {
foreach( $form['fields'] as &$field ) {
//NOTE: replace 3 with your checkbox field id
$field_id = 3;
if ( $field->id != $field_id ) {
continue;
}
// you can add additional parameters here to alter the posts that are retrieved
// more info: http://codex.wordpress.org/Template_Tags/get_posts
$posts = get_posts( 'numberposts=-1&post_status=publish' );
$input_id = 1;
foreach( $posts as $post ) {
//skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs)
if ( $input_id % 10 == 0 ) {
$input_id++;
}
$choices[] = array( 'text' => $post->post_title, 'value' => $post->ID );
$inputs[] = array( 'label' => $post->post_title, 'id' => "{$field_id}.{$input_id}" );
$input_id++;
}
$field->choices = $choices;
$field->inputs = $inputs;
}
return $form;
}发布于 2019-04-02 03:39:24
我想你想看看这句话,除非我弄错了:
$posts = get_posts( 'numberposts=-1&post_status=publish' );您应该能够添加orderby和order参数:
$posts = get_posts( 'numberposts=-1&post_status=publish&order=asc&orderby=title' );https://wordpress.stackexchange.com/questions/333173
复制相似问题