Add Below code in functions.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
function grab_ids_from_shortcode() { global $post; $attachment_ids = array(); $pattern = get_shortcode_regex(); $ids = array(); if (preg_match_all('/' . $pattern . '/s', $post->post_content, $matches)) { $count = count($matches[3]); for ($i = 0; $i < $count; $i++) { $atts = shortcode_parse_atts($matches[3][$i]); if (isset($atts[ids])) { $attachment_ids = explode(',', $atts[ids]); $ids = array_merge($ids, $attachment_ids); } } } return $ids; } |
Call Ids in theme File:
1 |
<?php grab_ids_from_shortcode(); /* This function return array */ ?> |