Wordpress Plugin, get HTML post content

妖精的绣舞 提交于 2020-01-01 12:05:11

问题


I am building a wordpress plugin, that acts when the admin saves a new post. I need to get the content of that post and i am retrieving $_POST['content'] and $_POST['post_content'].
The problem here is that i only get the text inside that content, i need the html.

This way, if i was expecting something like <p>Lorem</p><p>ipsum</p><p>dolor</p>, I get Lorem ipsum dolor.

Can someone help me please?

Thanks


回答1:


Well, as @ChrisCarson points out, Wordpress doesn't store paragraph tags in the database by default.

So, what I need to do, is parse the paragraphs myself using:

$content = explode(PHP_EOL . PHP_EOL, $this->request['content']);
$htmlcontent = '';
foreach($content as $line){
    $htmlcontent .= '<p>' . str_replace(PHP_EOL, '<br />' , $line) . '</p>';
}   

thanks anyway




回答2:


Wordpress doesn't store paragraph tags in the database by default. Try this...

$content = trim(stripslashes($_POST["post_content"]));
$html = apply_filters("the_content", $content);



回答3:


From the codex: http://codex.wordpress.org/Template_Tags/the_content#Alternative_Usage

If you want to achieve the same output that the_content() returns, use the following code:

<?php
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
?>


来源:https://stackoverflow.com/questions/6896655/wordpress-plugin-get-html-post-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!