This is working for me
$shortcode="book";
$pattern = get_shortcode_regex();
// if shortcode 'book' exists
if ( preg_match_all( "https://wordpress.stackexchange.com/". $pattern .'/s', $post->post_content, $matches )
&& array_key_exists( 2, $matches )
&& in_array( $shortcode, $matches[2] ) ) {
$shortcode_atts = array_keys($matches[2], $shortcode);
// if shortcode has attributes
if (!empty($shortcode_atts)) {
foreach($shortcode_atts as $att) {
preg_match('/id="(\d+)"https://wordpress.stackexchange.com/", $matches[3][$att], $book_id);
// fill the id into main array
$book_ids[] = $book_id[1];
}
}
...