In content I can have multiple shortcodes like [book id="1"] [book id="14" page="243"]
Is there any help method with which I can search the content for that shortcode and get its parameters? I need to get IDs so I can call WP_Query and append the Custom Post Types titles at the end.
function filter_books( $content ) {
// get all shortcodes IDs and other parameters if they exists
...
return $content;
}
add_filter( 'the_content', 'filter_books', 15 );
I tried using following code but var_dump($matches) is empty and if it would work I am not sure how would I get parameters (https://stackoverflow.com/questions/23205537/wordpress-shortcode-filtering-the-content-modifies-all-posts-in-a-list)
$shortcode = 'book';
preg_match('/\['.$shortcode.'\]/s', $content, $matches);
get_shortcode_regex
, all of the functions you'd need are in core.