I use get_pages()
to fetch the title and content of each of my top level pages and displays it on one page. Unfortunately it’s stripping out all of my <p>
tags and I’m not sure why. If the <p>
tag has a style or class to it, it will keep it, but all normal <p>
tags get stripped. Here is my code:
<?php
$pages = get_pages('parent=0');
foreach ($pages as $pagg) {
$option = '<div class="section">';
$option .= $pagg->post_title;
$option .= $pagg->post_content;
$option .= '</div>';
echo $option;
}
?>
EDIT:Alex was nice enough to provide the answer. The Solution below.
<?php
$pages = get_pages('parent=0');
foreach ($pages as $pagg) {
$option = '<div class="section">';
$option .= $pagg->post_title;
$option .= wpautop($pagg->post_content);
$option .= '</div>';
echo $option;
}
?>
You need to filter the content.
This will return formatted text, shortcodes that are processed and omebeds that work.
This would happen automatically if you called setup_postdata(), or used the content from the loop.
WordPress does not like
p
elements for some reason. Its WYSIWYG editor never (or rarely) inserts them.Run the string through
wpautop()
to add thep
elements.