Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress parses wp_posts.post_content before rendering?

Tags:

wordpress

I noticed that when I call the the_post() or the_content() function from my wordpress template, it automatically parses the database data to replace new lines with <br/>, wraps the text with <p> tags etc...There's probably some kind of "format" function within the_post() or the_content().

I wrote a query to directly get posts from the wp_posts. I then print it out like

<?php
$results = $wp->get_results($sql)
foreach($results as $row) echo $row->post_content; ?>

Clearly, this data is not parsed by wordpress' "format" function. What is the proper way to output this content such that it undergoes the same "formatting" functions as the_post() or the_content()?

like image 818
John Avatar asked Apr 10 '26 20:04

John


1 Answers

@dpelletier is right, and you can simply apply that function to the $row->post_content string.

If you want WordPress to do everything it would normally do on the content, including wpautop and parsing shortcode, use;

$content = apply_filters('the_content', $row->post_content);
like image 113
TheDeadMedic Avatar answered Apr 13 '26 22:04

TheDeadMedic