I have some PHP on my site which contains the following portion of code:
'choices' => array ('london' => 'London','paris' => 'Paris',),
Currently this list is static - I manually add to it however I want to generate the list dynamically.
I'm using the following code to create an array dynamically from WordPress & store in a variable:
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
}
Now, this is where I'm stuck :-)
How do I now assign $locations_list to 'choices'?
I tried 'choices' => $locations_list but it crashed my site.
Many thanks for any pointers.