私のサイトには、次のコード部分を含むPHPがあります。
'choices' => array ('london' => 'London','paris' => 'Paris',),
現在、このリストは静的です。手動で追加しますが、リストを動的に生成したいと思います。
次のコードを使用して、WordPressから動的に配列を作成し、変数に格納します。
function locations() {
query_posts(array('orderby' => 'date', 'order' => 'DESC' , 'post_type' => 'location'));
if (have_posts()) :
while (have_posts()) : the_post();
$locations = "'\'get_the_slug()'\' => '\'get_the_title()'\',";
endwhile;
endif;
wp_reset_query();
$locations_list = "array (".$locations."),";
return $locations_list; // final variable
}
さて、これは私が立ち往生しているところです:-)
$locations_list
に割り当てるにはどうすればよい'choices'
ですか?
試し'choices' => $locations_list
ましたが、サイトがクラッシュしました。
ポインタをありがとう。