We’ve been using the addon for adding galleries successfuly for a while but now we need to run multiple XML exports to other sites. The problem is all images are randomly placed in the XML we generate and they rarely appear in the way we have arranged them. I was wondering is there a way to save the image order into the database so all images will always appear in the way they are initially set up?
If you’re exporting to XML, it depends on what you’re using, but it’s probably outputing them in the order that they were uploaded to WP. Gallery images are WP Media files and these are posts that are exported. The only way to get them in the same order is if the tool you’re using to export to XML reads the value of the ACF field to reorder post IDs before output.
// post ID in second arg
// false in 3rd arg gets the unformatted value
// this will return an array in the order that the images
// are in the gallery
$gallery = get_field('your-gallery-field', $post_id, false);
// use this array to query the attachments
$query = new WP_Query(array(
// other query arguments
'post__in' => $gallery,
'orderby' => 'post__in'
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Clients need flexibility. Developers need a repeatable workflow that doesn’t have a steep learning curve. See how digital marketing agency Noiza found both with Advanced Custom Fields in our latest case study.https://t.co/BxQAy6COJt