【发布时间】:2022-06-25 21:57:30
【问题描述】:
我正在 wordpress API 中创建一些自定义路由。一切正常,但我在检索帖子的 post_content 时遇到问题。 json 中的格式无效。换行。
如果您使用 wp_strip_all_tags 删除所有 html 标记,它可以正常工作,但不能使用它。我想保留标签。
'descripcion' => get_post_field('post_content', $post->ID)
谢谢
【问题讨论】:
我正在 wordpress API 中创建一些自定义路由。一切正常,但我在检索帖子的 post_content 时遇到问题。 json 中的格式无效。换行。
如果您使用 wp_strip_all_tags 删除所有 html 标记,它可以正常工作,但不能使用它。我想保留标签。
'descripcion' => get_post_field('post_content', $post->ID)
谢谢
【问题讨论】:
你试过这样吗?
html_entity_decode(get_post_field('post_content', $post->ID), ENT_QUOTES, 'UTF-8');
或
htmlentities(get_post_field('post_content', $post->ID), ENT_QUOTES, 'UTF-8');
请阅读这两个函数的 PHP 文档。
【讨论】: