WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a number of external SQL tables that have data in exactly the way I want and I would like to use them to populate various wordpress posts with shortcodes.

The problem is that I don't understand how wordpress 'filters' text in get_content() so that the proper

are added.

IOW: I have a proper WP Post and I display the contents on a page it auto-magically includes

tags. If I copy that text to my external table and then pull that field into the same WP post using

$result = $wpdb->get_col( "SELECT my_text FROM my_songs WHERE id = '" . $song_id . "'" );   

...the results has none of the <br> or <p>s unless I explicitly add them to the text.

How can I take $result above and 'format' it so that it matches the same text from a WP Post using get_content() ?

share|improve this question
up vote 0 down vote accepted

You can run the the_content filters on your data.

foreach ($results as $r) {
  echo apply_filters('the_content',$r); 

That should get you the same formatting as in your posts.


share|improve this answer
Thanks. What I -had- been doing was apply_filters('the_content',$results[0]) and it didn't work. For -whatever- reason, adding that loop did the trick. Weird. – jchwebdev Feb 27 '13 at 23:19
apply_filters('the_content',$result[0]), not results[0] as you had it, works when I try, but only if you know you have only one result-- $wpdb->get_var would be a better method if that is the case. – s_ha_dum Feb 28 '13 at 0:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.