Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

The following code allows you to upload multiple images but only one is saved to the option. Can multiple images be saved to the option as an array or would I have to create separate controls?

$wp_customize->add_section("slider",array(
    'title'=>"Slider",
    'description'=>"Choose the images for the slider",
    'priority'=>'36'
));

//images
$wp_customize->add_setting("slider[images]",array(
    'default'=>"",
    'type'=>"option"
));
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize,"slider[images]",array(
    'label'=>__("Images","adaptive-framework"),
    'section'=>"slider",
    'settings'=>"slider[images]"
)));
share|improve this question
add comment

1 Answer

You define the setting as an array, however, you over and over reference the same entry slider[images].

$wp_customize->add_section("slider_images", array(
    'title' => "Slider",
    'description' => "Choose the images for the slider",
    'priority' => '36',
));

$wp_customize->add_setting("slider_images", array(
    'default' => "",
    'type' => "option",
));
$slider_images = get_setting('slider_images');
$num_images = 0;
if (is_array($slider_images) && ! empty($slider_images))
    $num_images = count($slider_images);
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, "slider_images[".$num_images."]", array(
    'label' => __("Images", "adaptive-framework"),
    'section' => "slider",
    'settings' => "slider_images",
)));

Note: I did not test this, and I never used WP's Theme Customization API before. And, of course, you need to take care of deleting images, and handling the remaining images/array entries and the like. This is just a (most probably not working) example.

If you want to store multiple entries in a single setting, use an array (e.g., slider_images). Then, to define one specific entry, reference the specific array entry (e.g., slider_images[0]).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.