在内容中,我可以有多个短代码,如[book id="1"] [book id="14" page="243"]
是否有任何帮助方法可以让我搜索该短代码的内容并获取其参数?我需要获取ID,以便调用WP\\u Query并在末尾附加自定义帖子类型标题。
function filter_books( $content ) {
// get all shortcodes IDs and other parameters if they exists
...
return $content;
}
add_filter( \'the_content\', \'filter_books\', 15 );
我尝试使用以下代码,但var\\u dump($matches)为空,如果它可以工作,我不确定如何获取参数(https://stackoverflow.com/questions/23205537/wordpress-shortcode-filtering-the-content-modifies-all-posts-in-a-list) $shortcode = \'book\';
preg_match(\'/\\[\'.$shortcode.\'\\]/s\', $content, $matches);