[wp-trac] [WordPress Trac] #43826: get_post_galleries() should return gallery blocks

WordPress Trac noreply at wordpress.org
Thu Aug 15 12:05:01 UTC 2019


#43826: get_post_galleries() should return gallery blocks
----------------------------+-----------------------------
 Reporter:  pento           |       Owner:  tellyworth
     Type:  task (blessed)  |      Status:  assigned
 Priority:  normal          |   Milestone:  Future Release
Component:  Media           |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  needs-patch     |     Focuses:  template
----------------------------+-----------------------------

Comment (by russhylov):

 Hi all.
 Have temporarity solution.

 When we insert new gallery into the post content, html view of gallery
 block look at this
 <!-- wp:gallery
 {"ids":[909,917,916,915,914,913,912,911,910],"linkTo":"media"} -->
 <ul class="wp-block-gallery columns-3 is-cropped">....
 All of we need its IDs of attachment posts.

 Add to custom meta of post ids block (only numbers in []). Then we can get
 custom metadata of the post and get IDs of attachments post which needed.
 So, in our script we can ids of attachments type post and show needed
 images
 {{{#!php
 <?php

 foreach ($posts as $post) {
     $meta = get_post_meta($post->ID, 'gallery');
     $ids= explode(',', $meta[0]);
     foreach ($ids as $id) {
       $atp_meta = get_post_meta($id);
       echo "<pre>";
         echo dirname($atp_meta['_wp_attached_file'][0])."<br>";  //  get
 the upload directory for needed images.
         var_export(unserialize($atp_meta['_wp_attachment_metadata'][0]));
 // get array of all intermediate images.
       echo "</pre>";
     }
   }

 }}}

 // Done. Profit :)

 [[Image(http://bendera.com.ua/screenshot.jpg)]]

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/43826#comment:38>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list