通过WP-API输出HTML元素


Outputting HTML elements through WP-API

我正在使用WP-API创建一个JavaScript应用程序,在那里我使用http请求从WordPress数据库中提取内容。对于一个普通的帖子,我并没有得到我期望的所有元素数据。

我将以下文本放入可视化编辑器中。

侦探们正在调查一名女子被可怕谋杀的事件,据称凶手嫌疑人试图吃掉她。

据了解,这名22岁的女子在南威尔士一家无家可归者宿舍发生的令人震惊的事件中被咬伤,面部严重受伤。

但旅馆的一些邻居也声称,袭击嫌疑人是一名食人行为,他在警察向他发射泰瑟枪后死亡。

格温特警方拒绝对这些指控发表评论。然而,一位了解调查情况的消息人士表示,食人行为现在是调查的一条线索。

我通过API请求帖子,获取它们,但希望在每个段落的开头和结尾获得带有p标签的内容。相反,我得到了这个:

"content": "Detectives are investigating the horrific murder of a woman amid claims that the suspected killer was trying to eat her.'r'n'r'nThe 22-year-old woman is known to have been bitten and suffered terrible facial injuries in the shocking incident at a hostel for homeless people in south Wales.'r'n'r'nBut some neighbours of the hostel have also claimed the suspected attacker, who died after police fired a Taser at him, subjected the woman to an act of cannibalism.'r'n'r'nGwent police are refusing to comment on the claims. However, a source with knowledge of the investigation said that cannibalism was now a line of inquiry.",

是我的WordPress编辑器有问题,还是编码有问题?我更像是一个JavaScript程序员,第一次使用WordPress是因为我想要一个简单的客户端界面。

我意识到了这个问题。我的functions.php中的以下行:

~remove_filter('the_content', 'wpautop');

这是在我开始项目时使用的WordPress下划线空模板中,并从内容中删除html。删除此代码解决了问题。