Last active
March 9, 2020 20:57
-
-
Save hullen/5443218 to your computer and use it in GitHub Desktop.
Extract images ids from gallery shortcode into post_content of the wordpress posts or custom post types.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* return $images_id array() | |
*/ | |
function get_gallery_attachments(){ | |
global $post; | |
$post_content = $post->post_content; | |
preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids); | |
$images_id = explode(",", $ids[1]); | |
return $images_id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment