最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How is it possible that a gallery doesn't have attachment ids?

programmeradmin3浏览0评论

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?

Share Improve this question asked Apr 12, 2020 at 2:27 Daniel SimmonsDaniel Simmons 1741 silver badge10 bronze badges 1
  • 1 attachment ids are not required for the [gallery] shortcode - developer.wordpress/reference/functions/gallery_shortcode – Michael Commented Apr 12, 2020 at 3:06
Add a comment  | 

1 Answer 1

Reset to default 0

Prior 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.

发布评论

评论列表(0)

  1. 暂无评论