Skip to content

Instantly share code, notes, and snippets.

@alenabdula
Last active March 17, 2024 20:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alenabdula/426e8e375e0e9108cb34 to your computer and use it in GitHub Desktop.
Save alenabdula/426e8e375e0e9108cb34 to your computer and use it in GitHub Desktop.
Using Custom Fields Suite to Create Gallery Loop, See: https://css-tricks.com/forums/topic/multiple-images-wordpress-custom-fields

##Setting Up Meta Data Fields##

  • Install/Activate Custom Fields Suite WordPress Plug-In, Docs
  • Create new Field Group called Gallery Meta Data
  • Add a Field called Gallery Images and set the type as Loop, fill out the rest of the required fields, for placement rules attach this custom meta data to WordPress type of Page or whatever your requirements are. Hit Publish Figure 1
  • Next, Add additional field called Image. Hit Update Figure 2
  • Next, drag Image, field we just created, under the Gallery Images it needs to be a child of the Loop, Hit Update Figure 3

##Adding Meta Data to Pages##

  • Edit page you wish to add the Gallery Images to Figure 4
  • Keep hitting Add Image to add additional images Figure 5

##Getting the Data##

  $gallery_images = CFS()->get('gallery_images');
  foreach ($gallery_images as $image) {
    echo '<img src="'.$image["image"].'"/>';
  }

Note: for get('gallery_images'), gallery_images is the value that matches the value specified in our initial setup of Custom Meta Data fields. See Figure 6

##Figures##

Figure 1

Figure 2

Figure 3

Figure 4

Figure 5

Figure 6

@metataggsolutions
Copy link

Can I Use Multiple Field For One Loop?

@YussufElarif
Copy link

Thanks for this! Been really helpful!

@fridalovborg
Copy link

THANKS!!

@mkotsovoulou
Copy link

When you create a page duplicate custom field group values do not get duplicated...
Is there a way to do it from sql or php?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment