Wordpress 如何获取短代码的特定部分?

Wordpress 如何获取短代码的特定部分?,wordpress,Wordpress,我有一个脚本,它根据带有标题的短代码捕获帖子中的所有图像,并将图像和标题输出到旋转木马 这就是短代码的外观: [caption id="attachment_52788" align="alignnone" width="435" caption="my caption"]<a href="#"><img src="image.jpg" alt="" title="my title" width="435" height="363" class="size-full wp-im

我有一个脚本,它根据带有标题的短代码捕获帖子中的所有图像,并将图像和标题输出到旋转木马

这就是短代码的外观:

[caption id="attachment_52788" align="alignnone" width="435" caption="my caption"]<a href="#"><img src="image.jpg" alt="" title="my title" width="435" height="363" class="size-full wp-image-52788" /></a>[/caption]
[caption id=“attachment_52788”align=“alignnone”width=“435”caption=“my caption”][/caption]
这是php代码,用于提取标题和图像

$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
    $output2 = preg_match_all('/caption="(.*?)"/', $post->post_content, $matches2);
    $gallery = $matches[1];
    $captions = $matches2[1];
    $count_of_captions = 0;
    foreach ($captions as $capt) {

        $js .= 'captions[' . $ii . '] = "' . $capt . '";' . "\n";
        $ii++;

        if ($capt != "") {
            $count_of_captions++;
        }
    }
$output=preg\u match\u all('//i',$post->post\u content,$matches);
$output2=preg_match_all('/caption=“(.*)/”,$post->post_content,$matches2);
$gallery=$matches[1];
$captions=$matches2[1];
$count_of_字幕=0;
foreach($标题为$capt){
$js.='captions['.$ii.]='.$capt.';'.“\n”;
$ii++;
如果($capt!=“”){
$count_of_字幕++;
}
}
所有这些都在旧的wordpress版本上起作用。现在wordpress以这种方式输出标题:

[caption id="attachment_52725" align="alignnone" width="440"]<img class="size-full wp-image-52725" src="image.jpg" alt="" height="347" /> my caption[/caption]
[caption id=“attachment_52725”align=“alignnone”width=“440”]我的字幕[/caption]
现在,标题位于图像标签之后。现在如何提取字幕?

我找到了答案

这部分

$output2 = preg_match_all('/caption="(.*?)"/', $post->post_content, $matches2);
替换为

$output2 = preg_match_all('/\/>(.*?)\[\/caption\]/u', $post->post_content, $matches2);
我找到了答案

这部分

$output2 = preg_match_all('/caption="(.*?)"/', $post->post_content, $matches2);
替换为

$output2 = preg_match_all('/\/>(.*?)\[\/caption\]/u', $post->post_content, $matches2);