我有一堆正则表达式,我想在我的帖子上运行这些正则表达式来更新post_content
字段中,当满足一系列条件时,其中一些条件需要来自ACF的各种值的组合。长话短说,我需要一种能够使用preg_replace
我一直在学习wp_insert_post_data
过滤,它可以工作,但它只适用于当前正在编辑的帖子。有没有办法在WordPress中做到这一点,我可以循环浏览所有帖子并以类似方式更新内容?
这是我目前拥有的。
add_filter(\'wp_insert_post_data\', \'mystuff\', 99, 2);
function mystuff($data, $post)
{
$content = $data[\'post_content\'];
$regex = \'/MYCRAZYREGEXSTUFF/\';
$match = preg_match($regex, $content, $matches);
if ($match) {
$updatedContent = preg_replace($regex, \'\', $content);
$data[\'post_content\'] = $updatedContent;
}
return $data;
}