Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
and

are added.

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

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
add comment

1 Answer

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.

http://codex.wordpress.org/Function_Reference/apply_filters

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
add comment

Your Answer

 
discard

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.