Settings page arrays
-
Hi,
I am having trouble getting the required array from the settings page. My markup is this:
<div id="tab-two"> <p></p> <table class="sortable-meta-table"> <thead> <th>Slide Heading</th> <th>Slide Paragraph</th> <th>Slide Image</th> </tr> </thead> <tbody> <tr> <td> <input type="text" name="custom_slider[slide_heading][]" class="widefat" value="<?php echo $slideHeading ?>"> </td> <td> <textarea name="custom_slider[slide_paragraph][]" class="widefat" rows="4"><?php echo $slideParagraph ?></textarea> </td> <td> <div class="image-meta-container"> <img src="<?php echo $slideImageUrl ?>" class="meta-image-preview" style="max-width: 250px"> <input class="meta-image-value hidden" type="url" name="custom_slider[slide_image_url][]" value="<?php echo $slideImageUrl ?>"> <input type="button" class="button meta-image-button" value="Upload Image"> <input type="button" class="button delete-custom-img" value="Delete Image"> </div> </td> </tr> <tr> <td> <input type="text" name="custom_slider[slide_heading][]" class="widefat" value="<?php echo $slideHeading ?>"> </td> <td> <textarea name="custom_slider[slide_paragraph][]" class="widefat" rows="4"><?php echo $slideParagraph ?></textarea> </td> <td> <div class="image-meta-container"> <img src="<?php echo $slideImageUrl ?>" class="meta-image-preview" style="max-width: 250px"> <input class="meta-image-value hidden" type="url" name="custom_slider[slide_image_url][]" value="<?php echo $slideImageUrl ?>"> <input type="button" class="button meta-image-button" value="Upload Image"> <input type="button" class="button delete-custom-img" value="Delete Image"> </div> </td> </tr> </tbody> </table>
When the options are save the output in SQL is this:
array ( 'slide_heading' => array ( 0 => '5h245gq34feqw', 1 => 'b4vqrewcqevrbtb5', ), 'slide_paragraph' => array ( 0 => 'fwy5324bq3rwveca', 1 => '4b4werqwevdc', ), 'slide_image_url' => array ( 0 => 'https://wpdev:8888/wp-content/uploads/2016/05/1.png', 1 => 'https://wpdev:8888/wp-content/uploads/2016/05/2.png', ), )
Does anyone know how I can get it to be in this format? :
array ( 'slide' => array ( 'slide_heading' => '5h245gq34feqw', 'slide_paragraph' => 'b4vqrewcqevrbtb5', 'slide_image_url' => 'b4vqrewcqevrbtb5', ), 'slide' => array ( 'slide_heading' => '5h245gq34feqw', 'slide_paragraph' => 'b4vqrewcqevrbtb5', 'slide_image_url' => 'b4vqrewcqevrbtb5', ), etc... )
Many Thanks
Nick
- The topic ‘Settings page arrays’ is closed to new replies.