Support » Plugins » Hacks » Get a post content with proper html tags

  • Hallo,
    i’m taking a post in this way inside an ajax request:

    $object_single_post = get_post($post_id);
    $content = $object_single_post->post_content;

    after this task the content of the $content variable is the post with no paragraphs, example:

    EX.1

    \r\nFirst paragraph\r\n\r\nSecond paragraph

    This post content when displayed in a post automatically becomes:

    EX.2

    <p>First paragraph</p>
    <p>Second paragraph</p>

    I’m trying to understand which wordpress function convert the content of the database ( EX.1 ) to the final post ( EX.2 )
    I can convert \r\n to <br /> but i don’t like very much this solution and i want the same conversion that wordpress does.

Viewing 2 replies - 1 through 2 (of 2 total)
  • What you are looking for is apply_filters(). This lets you apply the differnt filters used in the site, including the content formatting.

    $content = apply_filters ("the_content", $post->post_content);

    Thread Starter danycode

    (@danycode)

    This is exactly what I needed, thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get a post content with proper html tags’ is closed to new replies.