Wordpress如何使用python和REST API获得高级自定义字段内容



我正在使用Python的REST API从WordPress获取自定义字段内容。当我拉一个非自定义字段,如"Title",我可以成功地渲染它的代码:

post_title = post_data_dict.get('title', {}).get('rendered', '')

然而,使用自定义字段,我无法弄清楚这一点。现在我的代码看起来像这样:

video_content = post_data_dict.get('acf', {}).get('content', '')

但是这包含HTML格式。

任何提示将非常感激。谢谢你。

我发现这篇文章对我很有用:从字符串

中删除HTML标记的Python代码我刚才用了这个函数:

def cleanhtml(raw_html):
cleanr = re.compile('<.*?>')
cleantext = re.sub(cleanr, '', raw_html)
return cleantext
所以,我的新代码看起来像这样:
video_content = cleanhtml(post_data_dict.get('acf', {}).get('content', ''))

最新更新