Using get_pages() in wordpress is stripping out my <p> tags

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;
  }
 ?>

Related posts

Leave a Reply

2 comments

  1. You need to filter the content.

    apply_filters('the_content', $pagg->post_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.