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
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
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);
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(']]>', ']]>', $content);
?>