我启动了这个 PHP 函数。此功能用于填充 WordPress 中的下拉选择菜单。
acf/load_field 钩子可以帮助我轻松地将其钩入。请参阅此处的文档。http://www.advancedcustomfields.com/resources/filters/acfload_field/
这是我get_posts
用来查询我的circuit
post_type 的函数。这一点工作正常。
见下文...
function my_circuit_field( $field )
{
$circuits = get_posts(array(
"post_type" => "circuit",
"post_status" => "publish",
"orderby" => "menu_order",
"order" => "ASC",
"posts_per_page" => -1
));
$field['choices'] = array();
$field['choices'] = array(
0 => 'Select a circuit...'
);
foreach($circuits as $circuit){
$field['choices'] = array(
$circuit->post_title => $circuit->post_title
);
}
return $field;
}
add_filter('acf/load_field/name=event_calendar_circuit', 'my_circuit_field');
我遇到的问题是...
$field['choices'] = array(
0 => 'Select a circuit...'
);
没有加入到这个的前面......
foreach($circuits as $circuit){
$field['choices'] = array(
$circuit->post_title => $circuit->post_title
);
}
只有$circuits foreach
显示在我的下拉列表中,我希望“选择电路”作为下拉选择菜单中的第一个选项出现。
谁能帮我理解我哪里出错了?