PHP - 如何获得`<?php the_content(); ?>`作为字符串或将其转换为字符串

lis*_*aro 5 php wordpress

我使用了很多功能:

get_search_query() 
Run Code Online (Sandbox Code Playgroud)

获取搜索返回的值,并能够修改和使用字符串.

我需要知道一个函数来获取<?php the_content(); ?>字符串或如何将该函数返回到字符串中.

内容只是一个带有段落标签的简单单词,但是使用该功能我也得到了标签,我想得到文本,所以我可以将它添加到超链接.

dec*_*eze 9

我认为你正在寻找get_the_content(),这是有据可查的:http://codex.wordpress.org/Function_Reference/the_content

  • 虽然这*可能是最好的方法,但请注意`get_the_content()`*不是*只是`the_content()`,而是返回内容而不是打印.一个重要的区别是`get_the_content()`不会过滤内容.因此,例如,如果您使用短代码嵌入视频,联系表单等,则默认情况下这些方法不起作用.你还想在内容上运行`apply_filters("the_content",...)`.来自WP Codex的更多信息:https://codex.wordpress.org/Function_Reference/the_content#Alternative_Usage (4认同)

小智 5

如果您需要将其存储在具有 html 格式的变量中,请执行以下操作

apply_filters('the_content',$post->post_content)
Run Code Online (Sandbox Code Playgroud)