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() ?

1 Answer 1


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.


  • 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
    Commented Feb 27, 2013 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
    Commented Feb 28, 2013 at 0:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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