I have a function that looks at the attachment IDs from a normal gallery (let's ignore Gutenberg galleries for now, they have a different structure altogether):
\get_post_gallery( 0, False );
, this should give me an array that has the key ids
containing all attachment IDs.
Now, if we are to import the following .xml
file, the theme unit test data, we see that 2 posts are created, namely "Post Format: Gallery" and "Post Format: Gallery (Tiled)", now, visually, they look the same in terms of what you think they'd do:
However, "Post Format: Gallery (Tiled)" is a Jetpack gallery
(taken from the post's code):
[gallery type="rectangular" columns="4" ids="755,757,758,760,766,763" orderby="rand"]
and "Post Format: Gallery" is a normal gallery:
[gallery]
I rely on the ids
key being there for my function to work. What option am I missing here? It seems there is a way to create a gallery without having IDs provided.
As a side note, whenever I create a non-Gutenberg gallery, it actually works, the output I'm given for get_post_gallery
is:
array(4) { ["link"]=> string(4) "none" ["size"]=> string(6) "medium" ["ids"]=> string(8) "33,32,31" ["src"]=> array(3) { [0]=> string(68) "http://127.0.0.1/wordpress/wp-content/uploads/2020/04/5--300x200.jpg" [1]=> string(68) "http://127.0.0.1/wordpress/wp-content/uploads/2020/04/7--300x200.jpg" [2]=> string(68) "http://127.0.0.1/wordpress/wp-content/uploads/2020/04/6--300x200.jpg" } }
There are ids
. Am I dealing with a malformed xml file here?
I have a function that looks at the attachment IDs from a normal gallery (let's ignore Gutenberg galleries for now, they have a different structure altogether):
\get_post_gallery( 0, False );
, this should give me an array that has the key ids
containing all attachment IDs.
Now, if we are to import the following .xml
file, the theme unit test data, we see that 2 posts are created, namely "Post Format: Gallery" and "Post Format: Gallery (Tiled)", now, visually, they look the same in terms of what you think they'd do:
However, "Post Format: Gallery (Tiled)" is a Jetpack gallery
(taken from the post's code):
[gallery type="rectangular" columns="4" ids="755,757,758,760,766,763" orderby="rand"]
and "Post Format: Gallery" is a normal gallery:
[gallery]
I rely on the ids
key being there for my function to work. What option am I missing here? It seems there is a way to create a gallery without having IDs provided.
As a side note, whenever I create a non-Gutenberg gallery, it actually works, the output I'm given for get_post_gallery
is:
array(4) { ["link"]=> string(4) "none" ["size"]=> string(6) "medium" ["ids"]=> string(8) "33,32,31" ["src"]=> array(3) { [0]=> string(68) "http://127.0.0.1/wordpress/wp-content/uploads/2020/04/5--300x200.jpg" [1]=> string(68) "http://127.0.0.1/wordpress/wp-content/uploads/2020/04/7--300x200.jpg" [2]=> string(68) "http://127.0.0.1/wordpress/wp-content/uploads/2020/04/6--300x200.jpg" } }
There are ids
. Am I dealing with a malformed xml file here?
- 1 attachment ids are not required for the [gallery] shortcode - developer.wordpress/reference/functions/gallery_shortcode – Michael Commented Apr 12, 2020 at 3:06
1 Answer
Reset to default 0Prior to WordPress 3.5 there was no gallery editor, so the normal way of a gallery was inserted was just with the [gallery]
shortcode, which would output all images attached to (i.e. originally uploaded to) the post. This functionality still works for backwards compatibility reasons. If this sounds awful, then yes, yes it was.