Title: Getting an php Array from »Advanced Custom Fields Plugin« into Js-Function
Last modified: December 21, 2016

---

# Getting an php Array from »Advanced Custom Fields Plugin« into Js-Function

 *  [cgoldt](https://wordpress.org/support/users/cgoldt/)
 * (@cgoldt)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/getting-an-php-array-from-advanced-custom-fields-plugin-into-js-function/)
 * Hi,
 * I would like to use a PHP Array, that I’m retrieving in the WP-Loop into a javascript
   function, that I’m having in a separate js-file.
 * That’s how I’m echoing my php array (from Advanced Custom Fields) in the loop:
 *     ```
       $images = get_field('galerie');
           if( $images ): ?>
               <?php 
               $i = 0;
               foreach( $images as $image ): 
                   $i++;
                   ?>
                   <div class="slider">
                        <?php echo $image['url']; ?>');">
                   </div>
               <?php endforeach; ?>
           <?php endif; ?>
       ```
   
 * In the final code this would look like:
 *     ```
       <div class="slider">
          THERE_GOES_THE_IMG_URL_1
          THERE_GOES_THE_IMG_URL_2
          THERE_GOES_THE_IMG_URL_3
       </div>
       ```
   
 * But I need to use the Image URLs in my Vegas Slider JQuery Plugin. The code is
   in a separate custom.js file and looks like this:
 *     ```
       $(".slider").vegas({
             slides: [
                 { src: "THERE_GOES_THE_IMG_URL_1" },
                 { src: "THERE_GOES_THE_IMG_URL_2" },
                 { src: "THERE_GOES_THE_IMG_URL_3" }
             ]
         });
       ```
   
 * How can I pass the Image URLs from the php loop into the jQuery Plugin?
 * Thanks for your help!
    Cara

Viewing 1 replies (of 1 total)

 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [9 years, 4 months ago](https://wordpress.org/support/topic/getting-an-php-array-from-advanced-custom-fields-plugin-into-js-function/#post-8576869)
 * Use the function wp_localize_script to pass values from your PHP code to javascript:
 * [https://codex.wordpress.org/Function_Reference/wp_localize_script](https://codex.wordpress.org/Function_Reference/wp_localize_script)

Viewing 1 replies (of 1 total)

The topic ‘Getting an php Array from »Advanced Custom Fields Plugin« into Js-Function’
is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * Last activity: [9 years, 4 months ago](https://wordpress.org/support/topic/getting-an-php-array-from-advanced-custom-fields-plugin-into-js-function/#post-8576869)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
