このPHP関数を開始しました。この関数は、WordPress のドロップダウン選択メニューに入力することです。
acf/load_field フックは、これを簡単にフックするのに役立ちます。こちらのドキュメントを参照してください。http://www.advancedcustomfields.com/resources/filters/acfload_field/
これは、 post_typeget_posts
を照会するために使用する関数です。circuit
このビットは正常に動作します。
下記参照...
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
が表示されます。ドロップダウン選択メニューの最初のオプションとして「回線を選択」を表示したいと思います。
どこが間違っているのかを理解してくれる人はいますか?